Websphere中获取项目下.properties路径
2024-08-27 11:00:07
一:如果容器为Websphere,那下面为红色的地方不能加"/",如果为tomcat,则加上"/",
- String path = this.class.getResource("").getPath()+"config.properties";
- Properties properties= new Properties();
- properties.load(new FileInputStream(new File(path )));
如果你的config.properties在某个包下面,则把包同时带上,如:config.properties在com.df.util包下,则为:
- String path = this.class.getResource("").getPath()+"com/df/util/config.properties";
- Properties properties= new Properties();
- properties.load(new FileInputStream(new File(path )));
二:如果你的项目中用到了spring,那么也可这样获取,
- import org.springframework.core.io.Resource;
- import org.springframework.core.io.ClassPathResource;
- Resource resource = new ClassPathResource("config.properties"); //直接读取src下的,位于class文件之下
- Properties properties= new Properties();
- InputStream in = resource.getInputStream();
- properties.load(in);
最新文章
- 转:Log4j使用
- android 网络请求库的比较
- InnoDB的WAL方式学习
- 在iOS7中修改状态栏字体的颜色
- DFS与BFS
- SQL参数化
- 蓄水池抽样(原理&;实现)
- set-集合功能介绍
- CSS的常用属性
- Oracle:对用户的CREATE、ALTER、GRANT、REVOKE操作练习
- Java数据持久层框架 MyBatis之背景知识二
- RabbitMQ 队列
- consistent.go 源码阅读
- class path resource [spring/applicationContext.xml] cannot be opened because it does not exist
- cxPivotGrid导出数据
- The Kernel Boot Process.内核引导过程
- 第三方登录:新浪微博登录(OAuth2.0)
- 20155323刘威良 网络对抗《网络攻防》 Exp1 PC平台逆向破解(5)M
- Android -- MediaRecord
- 详解Paste deploy
热门文章
- linux编程vim设置
- Jenkins是什么?
- Ubuntu无法sudo提权,报当前用户不在sudoers文件中错误
- C#使用UUID生成ID
- 32.使用来MethodFilterInterceptor灵活拦截
- 用VB实现COM+组件配置
- Installing Eclipse Plug-ins from an Update Site with a self-signed certificate
- c# 后台调用接口接收传过来的json
- Maven(六) eclipse 使用Maven deploy命令部署构建到Nexus
- python 安装pyqt4