Can an InputSream be converted to a File file?

Can this be done?
[24 byte] By [blackmagea] at [2007-11-27 6:47:16]
# 1
You can read from an input stream and put what you've read into a file.It's not clear what you mean by a "File file".As opposed to what?Message was edited by: paulcw
paulcwa at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...
# 2

My real problem is I created a jar and tried to get a file with the File file=new File(url.toURI()) which created problems. One solution was using an InputStream to read the file, but how do I get it to file format?

And if it makes any difference, its an excel file.

And I mean file=new File(txt);

Message was edited by:

blackmage

blackmagea at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...
# 3

So. You have a jar file with an Excel file. And you want to launch Excel with this file do you?

Well there will be no magic conversion here. You need to extract the file from the jar. Save it somewhere as a file. Use the newly created file to launch Excel (I suppose with Desktop or something).

cotton.ma at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...
# 4
>> Well there will be no magic conversion herebut cotton, you are talking to the blackmage
TuringPesta at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...
# 5

File isn't really a format, but I see what you mean.

There must be a thousand examples of this in the various I/O tutorials. Basically, taking your File object, create a java.io.FileOutputStream. Then create a buffer of bytes. Then in a loop, read a buffer of data from the InputStream, and write it to the OutputStream. Repeat until there are no more bytes to read.

Poke around the I/O tutorials on this site and you'll find an example pretty quick.

paulcwa at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...
# 6
to quote kajbj:"Do people really try to copy files byte by byte? I have never seen that. It's very naive."Copy Files Faster http://sdnshare.com/view.jsp?id=401
TuringPesta at 2007-7-12 18:19:59 > top of Java-index,Java Essentials,Java Programming...