public class Mytest
public static void readFile(String fileName) {//传入参数fileName是要读取的资源文件的文件名如(file.properties)
InputStream in = null;
Properties pros = new Properties();
try {
if (null != fileName) {
//前提是资源文件必须和Mytest类在同一个包下
in = Mytest.class.getResourceAsStream(fileName);
//得到当前类的路径,并把资源文件名作为输入流
pros.load(in);
Enumeration en = pros.propertyNames();//得到资源文件中的所有key值
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
System.out.println("key=" + key + " value=" + pros.getProperty(key));
//输出资源文件中的key与value值
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("读取资源文件出错");
} finally {
try {
if (null != in) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("关闭流失败");
}
}
}
两种方式:
logger.info("====得到路径===="
+ AddTempLotteryUser.class.getResource("/").getPath());
InputStream in2 = new FileInputStream(AddTempLotteryUser.class
.getResource("/").getPath()
+ "UserInterfaceCenter.properties");
logger.info("输入流的大小:" + in2.available());
Properties p = new Properties();
try {
InputStream in1 = AddTempLotteryUser.class
.getResourceAsStream("/UserInterfaceCenter.properties");
System.out.println("count==" + in1.available());
p.load(in1);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
分享到:
相关推荐
java读取属性文件通用方法,以及日志记录
连接数据库全部写在属性文件中,通过读取属性文件来连接。
Java读取属性文件,可以参考参考。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
读取自定义属性文件内容,可以自己定义属性文件的名字,任何路径都可以
vc读取文件属性资料vc读取文件属性资料
java读取pdf文件作者、标题等属性
如何读取webroot文件下的属性文件
如何读取webroot文件下的属性文件
C语言对HDF文件数据集和属性的读写[文].pdf
Golang读取属性文件 用 安装 go get github.com/tjz101/goprop 属性 port = 2770 driverName = mysql dataSourceName = root:mysql99@tcp(127.0.0.1:3306)/capture?charset=utf8 maxOpenConns = 2000 maxIdleConns ...
以下是对在JAVA中读取属性文件的几种方法进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助
shp文件:地理信息系统,也被称作GIS,它主要的扩展类型是SHAPEFILE (.SHP),一个包含了矢量地理空间数据的流行文件格式,描述了几何形态,点,线和多边形,每一个都有他们各自的属性。 shape文件由ESRI开发,一个...
读取shp文件的代码,也可以读DBF属性
主要介绍了Python实现读取Properties配置文件的方法,结合实例形式分析了Python读取Properties配置文件类的定义与使用相关操作技巧,需要的朋友可以参考下
* 得到属性文件的值 */ public String getValueByPropertyKey(String key) { String value = null; if (checkPropertyFile()) { value = getValue(key); } return value; } /* * get Value ...
文件属性读写代码 vb C# 文件属性读写代码 vb C#
NULL 博文链接:https://xiaoxuejie.iteye.com/blog/1174273
vb.net获取文件的各种属性 vb.net获取文件的各种属性vb.net获取文件的各种属性