使用对用的util包下的properties包就可以了,这样我们有配置的话,写到一个properties文件中更直观。

这里写一个比较丑的例子:

package com.property;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties; public class MainProperty {
public static void main(String[] args) throws IOException {
Properties properties=new Properties();
//路径
String url=System.getProperty("user.dir");
System.out.println(url);
File dire=new File("");
String URI=dire.getCanonicalPath();
System.out.println(URI);
//包名
String packString=(new MainProperty()).getClass().getPackage().getName();
System.out.println(packString);
FileInputStream fis=new FileInputStream(url+"\\src\\main\\java\\com\\property\\my.properties");
properties.load(fis);
fis.close();
System.out.println("sitename:"+properties.getProperty("sitename"));
System.out.println("siteURL:"+properties.getProperty("siteURL"));
}
}

确实比较丑,里面没有自动获取到当前的配置路径。这里可以自己写一个,比如类似spring的获取当前路径下的配置文件ClassPathXmlApplicationContext的,等用的时候再写吧。还缺少了一个properties文件,里面写几个自己想要的键值对就好了,然后打印自己的内容。

最新文章

  1. cmake cannot find package
  2. python 面向对象(类)
  3. iOS 调用拍照、选择本地相册、上传功能---未完善。
  4. Eclipse程序员要掌握的常用快捷键
  5. vbs xml 解析
  6. Custom Date tag
  7. SVN中取消冲突conflict
  8. linux下Memcached安装以及PHP的调用
  9. 使MySQL 支持繁体字
  10. for循环例题
  11. 基于SAE+CodeIgniter3.0+管理端angularjs+前台amazeui的多用户博客系统V1.0--系统设计(一)
  12. 报错:loaded the "" nib but didn't get a UITableView
  13. HDU 5455 Fang Fang 水题,但题意描述有问题
  14. 宿主机共享文件夹给不同Linux虚拟机的方法
  15. MySQL数据库索引简介
  16. 结合JDK源码看设计模式——迭代器模式
  17. [BZOJ 4152][AMPPZ 2014]The Captain
  18. .net core使用ViewComponent将页面图片转码成base64
  19. js表单提交到后台对象接收
  20. vue缓存页面【二】

热门文章

  1. webservice jaxws header验证
  2. window环境mysql解压版配置
  3. luoguP3367 [模板]并查集
  4. Python repr() 函数
  5. C++的编译与连接
  6. raptor
  7. python2.7中可以使用到的一些模块地址
  8. 利用Python和webhook实现自动提交代码
  9. swift VFL - 父视图是scrollview 注意点
  10. LayDate 时间选择插件的使用介绍 (低版本1.0好像是)