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;
}
}