从JAR中的资源文件夹加载属性 [英] Load Properties from resources folder within JAR

查看:219
本文介绍了从JAR中的资源文件夹加载属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

类PropertiesUtils位于client.jar中(如图所示),属性文件位于属性文件夹,位于资源文件夹中。

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.

我正在尝试加载属性:

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

Any帮助很明显。提前致谢。

Any help is appreciable. Thanks in advance.

推荐答案

如果属性文件在jar文件中,则它不再是物理文件

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

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

这篇关于从JAR中的资源文件夹加载属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆