• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to read and write a jar file?

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, i got it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic