• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read and write a jar file?  RSS feed

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to copy a jar file and write its content with a new file name. But I found generated jar file becomes corrupted and has doubled size of the content. But I don't know where the code is wrong. Please take a look:



my generated blah_new.jar has almost doubled size as original file, blah.jar. Any idea why? Thanks.

I originally intend to download that jar file from a URL, but it's the same situation. Now even I just deal with it in the same directory, it's doing the same thing. Anything wrong on dealing with binary files?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by reubin haz:
Anything wrong on dealing with binary files?
Yes. Don't use a Reader for a binary file. Readers are for text. If you want buffering, a BufferedInputStream would work properly.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides that, you create a BufferedReader around the input stream but then ignore it except for closing.

If you create it, you should read from the buffered input stream. Who knows, perhaps it already reads a few bytes upon creation? Those bytes will not show up in the reading of the file input stream.
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, i got it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!