Scanner reading large file

前端 未结 2 764
囚心锁ツ
囚心锁ツ 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条回答
  •  無奈伤痛
    2020-12-11 05:28

    This issue is usually more common on 64 bit machines or with files having size more than 1-2 GB and does not have anything to do with heap space. Switch to BufferedReader it should work fine,

    BufferedReader br = new BufferedReader(new FileReader(filepath));
    String line = "";
    while((line=br.readLine())!=null)
    {
        // do something
    }
    

提交回复
热议问题