Scanner reading large file

前端 未结 2 766
囚心锁ツ
囚心锁ツ 2020-12-11 05:04

I am playing around with the Scanner class for learning purposes and i use it to read a very large file (60.000 lines aprox) without using the Reader class , and it stops re

2条回答
  •  -上瘾入骨i
    2020-12-11 05:37

    I just experienced this very problem. It seems that it works just by changing the scanner construction. Replace this:

    File file1 = new File("file1");
    Scanner in= new Scanner(file1);
    

    with this:

    FileReader file1 = new FileReader("file1");
    Scanner in= new Scanner(file1);
    

    Maybe the problem appears when you build your scanner from a file without the system knowing that it is a text file.

提交回复
热议问题