ExtJs + SpringMVC 项目中读取本地日志文件

来源:互联网 发布:奇异矩阵 编辑:程序博客网 时间:2024/05/21 15:04

1.先将所有文件名称,显示出来,点击装载文件内容。

   装载所有文件名称:

          读取文件名,

      

private static void getFile(String path){           // get file list where the path has           File file = new File(path);           // get the folder list           File[] array = file.listFiles();                     for(int i=0;i<array.length;i++){               if(array[i].isFile()){                   // only take file name                   System.out.println("^^^^^" + array[i].getName());                   // take file path and name                   System.out.println("#####" + array[i]);                   // take file path and name                   System.out.println("*****" + array[i].getPath());               }else if(array[i].isDirectory()){                   getFile(array[i].getPath());               }           }       }    

读取内容:

@Overridepublic String retrieveLogContent(String fileName,String id) {String output = "";File file = new File(logPath + File.separator + fileName);if (file.exists()) {if (file.isFile()) {try {BufferedReader input = new BufferedReader(new FileReader(file));StringBuffer buffer = new StringBuffer();String text;while ((text = input.readLine()) != null)buffer.append(text);output = buffer.toString();} catch (IOException e) {log.error("fail to read file:[" + e.getMessage() + "]");}} } else {log.warn("the specified file:[" + file.getAbsolutePath() + "] does not exists");}return output.length() == 0 ? "Sorry, we cannot find any content from this file" : output;}



原创粉丝点击