簡體   English   中英

從JAR中的資源文件夾加載屬性

[英]Load Properties from resources folder within JAR

我有一個JAR文件Movie Library.jar,其內容如下所示:

在此處輸入圖片說明

類PropertiesUtils駐留在client.jar中(如圖所示),屬性文件位於properties文件夾中,而properties文件夾位於resources文件夾中。

我正在嘗試將屬性加載為:

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);

但它顯示:

file:\D:\Code\MovieLibrary\build\jar\Movie%20Library.jar!\resources\properties\movie_library.properties (The filename, directory name, or volume label syntax is incorrect)

我無法將其視為System.out.println(file)打印:

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

任何幫助都是可觀的。 提前致謝。

如果屬性文件在jar文件中,則它不再是物理文件

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM