I have this line in my program :
InputStream Resource_InputStream=this.getClass().getClassLoader().getResourceAsStream("Resource_Name");
But how can I get FileInputStream from it [Resource_InputStream] ?
file-iojava
I have this line in my program :
InputStream Resource_InputStream=this.getClass().getClassLoader().getResourceAsStream("Resource_Name");
But how can I get FileInputStream from it [Resource_InputStream] ?
Best Answer
Use
ClassLoader#getResource()
instead if its URI represents a valid local disk file system path.If it doesn't (e.g. JAR), then your best bet is to copy it into a temporary file.
That said, I really don't see any benefit of doing so, or it must be required by a poor helper class/method which requires
FileInputStream
instead ofInputStream
. If you can, just fix the API to ask for anInputStream
instead. If it's a 3rd party one, by all means report it as a bug. I'd in this specific case also put question marks around the remainder of that API.