读取WEB-INF下的日志文件并添加到集合(windows和linux环境通用)
来源:互联网 发布:2017淘宝双12报名时间 编辑:程序博客网 时间:2024/05/16 10:00
public class getLogList{
//获取日志文件
public List<String> readTxtFile(){String logPath = this.getLogPath();
List<String> list=new ArrayList<String>();
try {
String encoding="GBK";
File file=new File(logPath);
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
list.add(lineTxt);
}
read.close();
}else{
logger.debug("找不到指定的文件");
}
} catch (Exception e) {
logger.debug(e.toString());
}
return list;
}
//不同环境下获取日志文件路径
public String getLogPath() {
String classPath = RuntimeLogController.class.getClassLoader().getResource("/").getPath();
String logPath="";
String rootPath = "";
String se=File.separator;
if("\\".equals(se)){//windows下
rootPath = classPath.substring(1,classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("/", "\\");
}
if("/".equals(se)){//linux下
rootPath = classPath.substring(0,classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
}
logPath=rootPath+se+"WEB-INF"+se+"data"+se+"logs"+se+"epolice.log";
return logPath;
}
}
0 0
- 读取WEB-INF下的日志文件并添加到集合(windows和linux环境通用)
- Java读取WEB-INF下XML文件并进行解析
- Java读取WEB-INF下XML文件并进行解析
- web项目中读取web-inf下的properties文件
- java web项目中的java读取WEB-INF和classes下的文件
- log4j生成的日志保存到项目WEB-INF下
- junit4 读取WEB-INF下得文件
- 跳转到WEB-INF目录下的文件和页面之间参数传递
- 读取web-inf里的文件
- web项目读取WEB-INF下properties文件
- 如何读取sd下的json文件,并解析展示,添加到数据库中
- Maven组织的web项目读取WEB-INF下properties文件
- Maven组织的web项目读取WEB-INF下properties文件
- 读取web项目web-inf目录下的jdbc.properties文件
- Junit 单元测试 Spring 读取WEB-INF下 xml 文件
- IDEA:将WEB-INF\lib下的Jar包添加到项目中
- java文件读取web-inf下的spring的xml配置文件
- Struts2取WEB-INF下的文件
- c++ 数据类型整理
- Linux——简单介绍
- nrf51822 --- 外部中断(按键2)
- MVP设计模式思路
- mybatis查询,如果返回类型为resultType时,查询不到某些属性值问题
- 读取WEB-INF下的日志文件并添加到集合(windows和linux环境通用)
- android客服端+eps8266+单片机+路由器之远程控制系统
- tomcat下的struts2+CDI(openwebbeans)+JPA配置
- Uboot 常用指令
- ToolBar + DrawerLayout
- SQL批量删除表、数据
- 网络编程笔记
- Kali Rolling在虚拟机安装后的设置
- 一致性哈希算法应用与分析