Reputation: 29806
I have a JAR file Movie Library.jar, its contents are depicted below:
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:\Code\MovieLibrary\build\jar\Movie%20Library.jar!\resources\properties\movie_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.
Upvotes: 2
Views: 12128
Reputation: 240870
If the property file is inside jar file, it is no longer a physical file
props.load(LazyProperties.class.getResourceAsStream("/properties/movie_libraryproperties"));
Upvotes: 6