File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes writing froma stream to a File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing froma stream to a File" Watch "writing froma stream to a File" New topic
Author

writing froma stream to a File

Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
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

Joined: Aug 05, 2005
Posts: 3742
    
  16
Where do you think you are writing something to the file ?


Joanne
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing froma stream to a File