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

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

问题描述

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

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

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

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

但它显示:

file:D:CodeMovieLibraryuildjarMovie%20Library.jar!
esourcespropertiesmovie_library.properties (The filename, directory name, or volume label syntax is incorrect)

我无法将其计算为 System.out.println(file) 打印:

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.

推荐答案

如果属性文件在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天全站免登陆