程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

java txt文件逐行读取

搞个日志的log分析下

package com.sdream.ls.client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
 
public class TXTParseUtils {
 
    private static final Integer ONE = 1;
 
    public static void main(String[] args) {
        /* 读取数据 */
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("D:\\Program Files (x86)\\Tencent\\WeChat\\voice_log (16).log")),
                    "UTF-8"));
            String lineTxt = null;
            while ((lineTxt = br.readLine()) != null) {
                if(lineTxt.indexOf("语音包解析转发完时间")>0){
                    System.out.println(""+lineTxt);
                }
            }
            br.close();
        } catch (Exception e) {
            System.err.println("read errors :" + e);
        }
    }


}

 

赞(0)
未经允许不得转载:程序员一代码搬运工 » java txt文件逐行读取
分享到: 更多 (0)