aspose file tools
The moose likes Beginning Java and the fly likes make FileInputStream out of InputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "make FileInputStream out of InputStream" Watch "make FileInputStream out of InputStream" New topic

make FileInputStream out of InputStream

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Is it possible to make FileInputStream out of InputStream? If so, could someone please point me to some code examples?
Thanks a lot.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19308

No, it isn't.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Well, you could read everything from the original InputStream. write it to a file, and then open a new FileInputStream to read the file you just wrote. In general that sounds rather silly and inefficient - why do you need a FileInputStream as opposed to an InputStream? But perhaps it might be necessary in some case.

It's also possible to create your own FileInputStream class which overrides all the regular FileInputStream methods and replaces them with methods that read from the other InputStream instead. This is probably a horrible, ugly idea. But it's possible.

I think that in all likelihood, you need to examine why you need a FileInputStream here. There's probably going to be a better way to accomplish what you're trying to do.

"I'm not back." - Bill Harding, Twister
It is sorta covered in the JavaRanch Style Guide.
subject: make FileInputStream out of InputStream