This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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: 19869

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
I agree. Here's the link:
subject: make FileInputStream out of InputStream
It's not a secret anymore!