Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a JAR file Movie Library.jar, its contents are depicted below:

enter image description here

The class PropertiesUtils is resides in the client.jar (shown in picture) and the properties files are in properties folder which resides in resources folder.

I am trying to load properties as:

String absolutePath = LazyProperties.class.getClass().getResource(filePath).getPath();
File file = new File(absolutePath);
InputStream stream = new FileInputStream(file);
Properties properties = new Properties();
properties.load(stream);

But it is showing:

file:D:CodeMovieLibraryuildjarMovie%20Library.jar!
esourcespropertiesmovie_library.properties (The filename, directory name, or volume label syntax is incorrect)

I am unable to figure it as System.out.println(file) prints:

file:/D:/Code/MovieLibrary/build/jar/Movie%20Library.jar!/resources/properties/movie_library.properties

Any help is appreciable. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
459 views
Welcome To Ask or Share your Answers For Others

1 Answer

If the property file is inside jar file, it is no longer a physical file

props.load(LazyProperties.class.getResourceAsStream("/properties/movie_libraryproperties"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...