Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reducing the File Size  RSS feed

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at the following code



In here, I am getting a file (any kind) and convert it to a .txt file by getting its bytes. if the file is 6MB big, the .txt file also 6MB big. But I need to reduce the size of the .txt file. I tried it by splitting the .txt file into 56000 .txt files and compressing it, but no good. How can I reduce the size of the .txt file ? (Note that if I change its content, the file will be useless because then I can't re-set the .txt file to its original format). What I have heard up to now is this is impossible, but I don't believe it, I believe nothing is impossible. Please help...
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is impossible to reduce the file size without altering its contents. That should be obvious. You're saying, "Keep it exactly the same, but make it smaller."

You can however compress the size, changing the contents, but without losing any information. I suspect this is what your real concern is. Google for something like java file compression, or java zip api tutorial.

Also, copying a .avi file to .txt is pointless, and can lead to confusion. It's not a text file, and you won't be able to read it with a text editor. It's still the exact same file in the exact same format with the exact same bytes. All you've done is give it an extension that makes it look like it's something that it's not.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried that zip package, but it didn't work. It is OK to alter anything if it is not going to destroy the original file it contains. Please help
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:ItDoesntWorkIsUseless.


Oh sorry, I beg your apologies Rob. Actually why I said it didn't work is because java's zip package reduced only 1MB. I need to reduced LOT more than that. I am ready to spend years of research of this, even ready to learn any kind of technology which can apply. Please help....
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes there isn't much to compress. In your code you use an AVI file as an example. That's most likely already compressed quite a bit.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you all mean there is no way?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already said, compression can only go so far in reducing file sizes.

WP
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yohan Weerasinghe wrote:So, you all mean there is no way?



Unless of course, you drop your lossless requirement.... throw the avi file into an video editor, switch to a lossy codec, and you can get almost any amount of compression you want -- you just have to be prepared to lose some framerate, gain some pixelation, muffle the sound, etc.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!