Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert InputStream into FileInputStream

Tags:

java

iostream

I have read this post How to convert InputStream to FileInputStream on converting a InputStream into a FileInputStream. However, the answer does not work if you are using a resource that is in a jar file. Is there another way to do it.

I need to do this to get the FileChannel from a call to Object.class.getResourceAsStream(resourceName);

like image 808
user489041 Avatar asked Dec 13 '22 15:12

user489041


1 Answers

You can't, without basically writing to a file. Unless there's a file, there can't be a FileInputStream or a FileChannel. If at all possible, make sure your code is agnostic to the input source - design it in terms of InputStream and ByteChannel (or whatever kind of channel is most appropriate).

like image 173
Jon Skeet Avatar answered Dec 28 '22 11:12

Jon Skeet