Loop through each line of data in the text

java code:

package com.zltest.bd;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class FileRead {
    public static void main(String[] args) throws Exception {
        File file = new File("D:\\aa.txt");
        InputStreamReader read = new InputStreamReader(new FileInputStream(file),"gbk");
        BufferedReader reader = null;
        String temp = null;
        int line = 1;
        try {
            reader = new BufferedReader(read);
            while ((temp = reader.readLine()) != null) {
                System.out.println("line" + line + ":" + temp);
                line++;
            }
        } catch (Exception e) {
            e.printStackTrace ();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception e) {
                    e.printStackTrace ();
                }
            }
        }
    }
}

 

The content of the text:

 

What the console output:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324790475&siteId=291194637