How to use quot;getResourceAsStreamquot; to get a file stream???
Hello,
I am doing the Spring application project. In my service layer, I want to get a file stream by using getResourceAsStream, but I just do not what to write before the .getResourceAsStream in my code.Code:
InputStream reportStream =???.getResourceAsStream(quot;file:/home/jars/files/report.jasperquot;);
What should I write to replace the ??? in above code??
PS: I try to use InputStream reportStream =getClass().getResourceAsStream(quot;file:/home/jars/files/report.jasperquot;);
But there is a warning on console.
Code:WARN org..beans.factory.support.PropertiesBeanDefinitionReader - Use of 'class' property in [org..beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'
Originally Posted by mellonHello,
I am doing the Spring application project. In my service layer, I want to get a file stream by using getResourceAsStream, but I just do not what to write before the .getResourceAsStream in my code.Code:
InputStream reportStream =???.getResourceAsStream(quot;file:/home/jars/files/report.jasperquot;);
What should I write to replace the ??? in above code??
PS: I try to use InputStream reportStream =getClass().getResourceAsStream(quot;file:/home/jars/files/report.jasperquot;);
But there is a warning on console.
Code:WARN org..beans.factory.support.PropertiesBeanDefinitionReader - Use of 'class' property in [org..beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'I had a hard time understanding what you were trying to.
You should into the Resource abstraction -- it provides a 'getInputStream()' method, which seems like what you're looking for:
sp.../Resource.html
Hi Mellon,
InputStream is = new BufferedInputStream( this.getClass(). getClassLoader(). getResourceAsStream(quot;filename));
Cheers,
Sreeram |