java - InputStream from jar-File returns always null -


i know question has been asked several times, think problem differs bit others:

string resourcepath = "/path/to/resource.jar";  file newfile = new file(resourcepath); inputstream in1 = this.getclass().getresourceasstream(resourcepath); inputstream in2 = this.getclass().getclassloader().getresourceasstream(resourcepath); 

the file-object newfile fine (the .jar file has been found , can meta-data newfile.length() etc)

on other hand inputstream return null. know javadoc says getresourceasstream() null if there no resource found name, file there! (obviously, because it's in file-object)

anyone know why happens , how can fix can .jar file in inputstream?

the getresourceasstream() method doesn't load file file system; loads resource classpath. can use load, example, property file that's packaged inside jar. cannot use load file file system.

so, if file resides on file system, rather in jar file, better use fileinputstream class.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -