我有一个JAR文件Movie Library.jar,其内容如下所示:
AttributeUtils类位于client.jar中(如图所示),属性文件位于属性文件夹中,该文件夹位于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:/D:/Code/MovieLibrary/build/jar/Movie%20Library.jar!/resources/properties/movie_library.properties
任何帮助都很明显.提前致谢.
解决方法:
如果属性文件在jar文件中,则它不再是物理文件
props.load(LazyProperties.class.getResourceAsStream("/properties/movie_libraryproperties"));