Java 代码读取properties文件
jdk1.6
package read;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class FileRead {
public static void main(String[] args) {
FileRead re=new FileRead();
String x=re.gete();
System.out.println(x);
}
public String gete(){
Properties props = new Properties();
System.out.println(new File("").getAbsolutePath());
try {
props.load(new InputStreamReader(new FileInputStream(new File("").getAbsolutePath()+"/src/config/read.properties"), "UTF-8"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String isuse = props.getProperty("ISUSE");
return isuse;
}
}
jdk1.7及以上
import java.io.InputStream;
import java.util.Properties;
Properties pro = new Properties();
try(InputStream is = getClass().getResourceAsStream(
"/config/Multi-Language-Configuration.properties")) {
pro.load(is);
} catch (Exception e) {
}
String isuse = pro.getProperty("ISUSE");
最新文章
- d3 document
- JavaScript基础—闭包,事件
- PHP中PSR-[0-4]代码规范
- (C#) Interview Questions.
- 《linux内核设计与实现》读书笔记第一、二章
- 2014.12.05(解决eclipse的adb打不开)
- QT的文本加密方法(寒山居士)
- 菜农群课笔记之ICP与ISP----20110412(整理版)
- 关于接收POST请求 $GLOBALS['HTTP_RAW_POST_DATA']
- HDU 5776 sum
- Docker入门01——Image
- treeview插件使用:根据子节点选中父节点
- Maven编译问题
- Let's Encrypt,站点加密之旅
- qt布局管理-缩放、多窗口切换
- ASP.NET MVC 4 从示例代码展开,连接默认SQL Server数据库
- 使用 ISO镜像配置 本地yum 源(RHEL, CentOS, Fedora等适用)
- 《Inside C#》笔记(十五) 非托管代码 上
- Cpu 主频与睿频
- IdentityServer4-端点
热门文章
- 简单python脚本,将jupter notebook的ipynb文件转为pdf(包含中文)
- mvn ssm 异常 org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'multipartResolver'
- Spring-Cloud-Eureka实例
- 配置centos7阿里镜像源和epel源
- Linux下MySQL的操作(最全)
- [Codeforces1148C]Crazy Diamond——构造
- c标签页面进行解析json
- QQ 为什么以 UDP 协议为主,以 TCP 协议为辅?
- 作妖 | ";该文件没有与之关联的程序来执行该操作...";的解决方法(删除快捷方式小箭头所致)
- arcgis python 刷新