一:如果容器为Websphere,那下面为红色的地方不能加"/",如果为tomcat,则加上"/",

  1. String  path = this.class.getResource("").getPath()+"config.properties";
  2. Properties properties= new Properties();
  3. properties.load(new FileInputStream(new File(path )));

如果你的config.properties在某个包下面,则把包同时带上,如:config.properties在com.df.util包下,则为:

  1. String  path = this.class.getResource("").getPath()+"com/df/util/config.properties";
  2. Properties properties= new Properties();
  3. properties.load(new FileInputStream(new File(path )));

二:如果你的项目中用到了spring,那么也可这样获取,

  1. import org.springframework.core.io.Resource;
  2. import org.springframework.core.io.ClassPathResource;
  3. Resource resource = new ClassPathResource("config.properties");  //直接读取src下的,位于class文件之下
  4. Properties  properties= new Properties();
  5. InputStream in = resource.getInputStream();
  6. properties.load(in);

最新文章

  1. 转:Log4j使用
  2. android 网络请求库的比较
  3. InnoDB的WAL方式学习
  4. 在iOS7中修改状态栏字体的颜色
  5. DFS与BFS
  6. SQL参数化
  7. 蓄水池抽样(原理&实现)
  8. set-集合功能介绍
  9. CSS的常用属性
  10. Oracle:对用户的CREATE、ALTER、GRANT、REVOKE操作练习
  11. Java数据持久层框架 MyBatis之背景知识二
  12. RabbitMQ 队列
  13. consistent.go 源码阅读
  14. class path resource [spring/applicationContext.xml] cannot be opened because it does not exist
  15. cxPivotGrid导出数据
  16. The Kernel Boot Process.内核引导过程
  17. 第三方登录:新浪微博登录(OAuth2.0)
  18. 20155323刘威良 网络对抗《网络攻防》 Exp1 PC平台逆向破解(5)M
  19. Android -- MediaRecord
  20. 详解Paste deploy

热门文章

  1. linux编程vim设置
  2. Jenkins是什么?
  3. Ubuntu无法sudo提权,报当前用户不在sudoers文件中错误
  4. C#使用UUID生成ID
  5. 32.使用来MethodFilterInterceptor灵活拦截
  6. 用VB实现COM+组件配置
  7. Installing Eclipse Plug-ins from an Update Site with a self-signed certificate
  8. c# 后台调用接口接收传过来的json
  9. Maven(六) eclipse 使用Maven deploy命令部署构建到Nexus
  10. python 安装pyqt4