Using BufferedReader to read Text File

前端 未结 9 1464
你的背包
你的背包 2020-11-29 04:29

I\'m having problems with using the BufferedReader

I want to print the 6 lines of a text file:

public class Reader {

public static void main(String[         


        
9条回答
  •  醉梦人生
    2020-11-29 05:07

    Maybe you mean this:

    public class Reader {
    
    public static void main(String[]args) throws IOException{
    
        FileReader in = new FileReader("C:/test.txt");
        BufferedReader br = new BufferedReader(in);
        String line = br.readLine();
        while (line!=null) {
            System.out.println(line);
            line = br.readLine();
        }
        in.close();
    
    }
    

提交回复
热议问题