如何读取jar中的属性文件? [英] How to read properties file inside jar?

查看:65
本文介绍了如何读取jar中的属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在com.abc.properties包下有一个config.properties文件.从com.abc.util中存在的Java类之一中,我需要读取属性文件.这两个文件都在jar中.我尝试使用

I have a config.properties file under the package com.abc.properties. From one of the java class present in com.abc.util, I need to read the property file. Both the files are present inside jar. I have tried using

fs = new FileInputstream(VerifyFolderStructure.class.getResourceAsStream("com/abc/properties/config.properties"));

但是它似乎不起作用.请帮忙.

But it doesn't seem to work. Please help.

P.S:VerifyFolderStructure是我的Java类,需要从中加载属性文件.

P.S: VerifyFolderStructure is my java class from which I need to load the properties file.

推荐答案

要获取流,您根本不需要FileInputStream.您可以像这样获取属性的文件流

To obtain the stream you don't need FileInputStream at all. You can get the properties' file stream like this

InputStream is = VerifyFolderStructure.class.getResourceAsStream("/com/abc/properties/config.properties");

这篇关于如何读取jar中的属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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