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

后端 未结 3 2002
南笙
南笙 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:35

    As the comments have indicated, your code is slow because you're attempting to load a number with a lot of digits.

    If you're unsatisfied with the performance of Java's BigInteger implementation, then I suggest you look elsewhere.

    This library claims to have a BigInteger that outperforms Java's implementation (note it may not speed up loading the number, but it should improve multiplication and division performance).

提交回复
热议问题