当前位置: 代码迷 >> J2EE >> 用IO流解析apache日志,该如何处理
  详细解决方案

用IO流解析apache日志,该如何处理

热度:87   发布时间:2016-04-22 01:27:37.0
用IO流解析apache日志
路径应该怎么写,才能读取出来保存到表里

------解决方案--------------------
Java code
public class ParseFile {    /**     * @param path        文件路径     * @param start        指针开始位置     * @param len        要读取的行数     * @throws Exception     */    public static void readFile(String path , long start , long len) throws Exception{        File file = new File(path);        RandomAccessFile raf = new RandomAccessFile(file, "r");        raf.seek(start);        String line = null;        long totalLen = 0 ;        while(totalLen < len && (line = raf.readLine()) != null){            System.out.println(line);            totalLen++;        }        long endPoint = raf.getFilePointer();    //得到读取完指定内容后指针位置        //这里可以将endPoint保存到数据库或文件  ,方便下次取出endPoint 然后接着读    }    public static void main(String[] args) throws Exception {        readFile("C:\\Documents and Settings\\zhoufeng\\桌面\\MappingJacksonHttpMessageConverterv2.java", 60 , 2    );    }}
  相关解决方案