Sir Rugmuncher Posted January 11, 2009 Share Posted January 11, 2009 Hello... If I have an input stream of a file as a byte array or a string, how would I go about writing this file to my pc? I have tried BufferedOutputStream fileWriter = new BufferedOutputStream(new FileOutputStream(new File("c:\\Files\"+filename))); fileWriter.write(stream info here) But all i get is a file with the right length and name but nothing in it, or no image to see... What am i missing? Thanks Link to comment Share on other sites More sharing options...
0 eFX Posted January 11, 2009 Share Posted January 11, 2009 Look at the code at the following page: http://en.wikipedia.org/wiki/New_I/O Link to comment Share on other sites More sharing options...
0 Sir Rugmuncher Posted January 11, 2009 Author Share Posted January 11, 2009 I looked at that page and couldn't see how it would help me.... Link to comment Share on other sites More sharing options...
0 JamesCherrill Posted January 11, 2009 Share Posted January 11, 2009 You need a loop in which you read data from the input stream and write it to the output stream until you reach end of file. Link to comment Share on other sites More sharing options...
0 Sir Rugmuncher Posted January 11, 2009 Author Share Posted January 11, 2009 I already have the information in a String/byte array but my problem is that the information is for example of an image... not a .txt file. My question is how can I write data for the different data types? it is not enough to place them as if they are a .txt file and change the file extension Link to comment Share on other sites More sharing options...
Question
Sir Rugmuncher
Hello...
If I have an input stream of a file as a byte array or a string, how would I go about writing this file to my pc? I have tried
BufferedOutputStream fileWriter = new BufferedOutputStream(new FileOutputStream(new File("c:\\Files\"+filename))); fileWriter.write(stream info here)But all i get is a file with the right length and name but nothing in it, or no image to see...
What am i missing?
Thanks
Link to comment
Share on other sites
4 answers to this question
Recommended Posts