while EOF in JAVA?

后端 未结 7 1406
难免孤独
难免孤独 2020-12-17 06:21

Following to some forums answers I\'m using this:

    while (fileReader.nextLine() != null) {
        String line = fileReader.nextLine();
        System.out         


        
7条回答
  •  -上瘾入骨i
    2020-12-17 06:37

    To read a file Scanner class is recommended.

        Scanner scanner = new Scanner(new FileInputStream(fFileName), fEncoding);
        try {
          while (scanner.hasNextLine()){
             System.out.println(scanner.nextLine());
          }
        }
        finally{
          scanner.close();
        }
    

提交回复
热议问题