• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing froma stream to a File

 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm Trying to write to a file. what exactly do i need to correct here. Right now it just keeps creating an empty file. Why's that?


[ December 11, 2007: Message edited by: Wolfgang Obi ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you think you are writing something to the file ?
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to read from the input stream, then copy that to the output stream.

You can do this byte per byte using the read() and write(int) methods, but experience has tought me that using the read(byte[]) and write(byte[], int, int) methods are a lot faster most of the times.

If you're using the byte[] versions, don't forget that read(byte[]) returns the number of bytes actually read. Don't always just go writing the entire array - you'll write garbage at the end of the file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic