2

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:\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.

Tapas Bose
  • 28,796
  • 74
  • 215
  • 331

1 Answers1

6

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

props.load(LazyProperties.class.getResourceAsStream("/properties/movie_libraryproperties"));
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Thanks @Jigar `LazyProperties.class.getResourceAsStream("/resources/properties/movie_library.properties")` did the job. Can you tell me what is the syntax if the resources folder be placed in client.jar? – Tapas Bose Feb 19 '12 at 12:25
  • 2
    `LazyProperties.class.getResourceAsStream("classpath:/resources/properties/movie_library.p‌​roperties")` – jmj Feb 19 '12 at 12:28
  • @JigarJoshi : Is there any way if I want to do changes in the property file inside the jar. ? – Harshil Apr 19 '16 at 12:46