How can I quickly load a large txt file into BigInteger?

后端 未结 3 2003
南笙
南笙 2020-12-04 02:06

I\'m importing a large text file, 17 million digits long and I\'m using this code:

BufferedReader reader = new BufferedReader(new FileReader(\"test2         


        
3条回答
  •  有刺的猬
    2020-12-04 02:42

    As an optimization, since BigInteger is Serializable, you could save it to a binary file once and speed up your loading considerably.

    Loading a serialized object should be way faster than parsing a huge string everytime.

    Use ObjectOutputStream to save your big integer and ObjectInputStream to read it back in.

提交回复
热议问题