package com.example.readproperties;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Main {
private static Properties properties;
/**
* @param args
*/
public static void main(String[] args) {
InputStream in = Main.class.getClassLoader().getResourceAsStream(
"aaa.joe");// -------备注1
properties = new Properties();
try {
properties.load(in);// 将输入流加载到配置对象,以使配置对象可以读取config.propertis信息
/**
* 打印结果:主机:124.207.190.251
端口号:33133
最大线程数:30
*/
System.out.println("主机:" + getHost() + "\n" + "端口号:" + getPort()
+ "\n" + "最大线程数:" + getTaskqueuesize());
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getHost() {
return "" + properties.get("host");
}
public static String getPort() {
return "" + properties.get("port");
}
public static String getTaskqueuesize() {
return "" + properties.get("taskqueuesize");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ReadProperties读取java项目配置文件
共9个文件
joe:2个
properties:2个
java:1个
5星 · 超过95%的资源 需积分: 13 102 下载量 145 浏览量
2013-11-26
10:56:42
上传
评论
收藏 6KB ZIP 举报
温馨提示
参考博文: http://blog.csdn.net/joe_storm/article/details/16960735
资源推荐
资源详情
资源评论
收起资源包目录
ReadPropertiesDemo.zip (9个子文件)
ReadPropertiesDemo
bin
com
example
readproperties
Main.class 2KB
config.properties 43B
aaa.joe 43B
.settings
org.eclipse.jdt.core.prefs 629B
src
com
example
readproperties
Main.java 1KB
config.properties 43B
aaa.joe 43B
.project 394B
.classpath 301B
共 9 条
- 1
资源评论
- zhang4648522782014-10-10挺好用的,学习了。
- wangshao_yizhan2015-08-04例子挺好的,解决现有问题,而且没有要资源分,感觉很好
- 灰帅2015-06-24挺好的,已经解决问题
- godlovewang2017-08-12可以用,已经用到项目中了。
亲爱的Joe
- 粉丝: 37
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功