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] ?
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] ?
Use ClassLoader#getResource()
instead.
URL resource = classLoader.getResource("Resource_Name");
File file = new File(resource.toURI());
FileInputStream input = new FileInputStream(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 of InputStream
. If you can, just use InputStream
instead.
Long story short: Don't use FileInputStream as a parameter or variable type. Use the abstract base class, in this case InputStream instead.