(java 功能篇)java 读取Propety配置文件
java哥
阅读:700
2021-04-01 10:17:39
评论:0
java效果代码:
源代码:
package com.rf.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ReadProperties {
public String[] getProper() {
// 读取配置文件属性类
Properties prop = new Properties();
try {
// 配置文件的输入流
InputStream is = this.getClass().getResourceAsStream("ui.property");
// 配置文件加载
prop.load(is);
if (is != null) {
is.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] res = { prop.getProperty("serverName"),
prop.getProperty("port"), prop.getProperty("dbType"),
prop.getProperty("dbName"), prop.getProperty("port"),
prop.getProperty("pswd"), prop.getProperty("UserSchema"),
prop.getProperty("table"), prop.getProperty("fullTable"),
prop.getProperty("sql"), prop.getProperty("name") };
return res;
}
/**
* @param args
*/
public static void main(String[] args) {
ReadProperties pro = new ReadProperties();
String[] res = pro.getProper();
for (String result : res) {
System.out.println(result);
}
}
}
效果截图:
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。



