首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

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

2012-05-21 
用IO流解析apache日志路径应该怎么写,才能读取出来保存到表里[解决办法]Java codepublic class ParseFile

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

热点排行