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 OutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OutputStream" Watch "OutputStream" New topic
Author

OutputStream

Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
I have used a FileInputStream and InputStream reader to read from a file. I have a function which takes the filename and an OutputStream and then writes to the OutputStream. I want to declare the OutPutStream in main and then pass it to this function so I can write to the OutputStream. I would I declare an OutputStream and then pass it to this function so I can write to it. Thanks
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Umm... simply pass the reference to the method and use it in there? If all you want to do is create it in main, but actually do the writing in another method, all you have to do is pass that reference to the method.
Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
But how would I declare it in main. When I do this Outputstream out; and then pass out to the method, I get an error?
Jeff Smith
Ranch Hand

Joined: May 04, 2001
Posts: 50
You need to say OutputStream out = null; not just OutputStream out; otherwise it'll give you an error saying 'out' hasn't been initialized or something.
Jeff
[ April 08, 2002: Message edited by: Jeff Smith ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutputStream