Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading huge textfiles Java

I've got a .txt with 1 Billion digits of pi. I read in the file as a String but i get an OutOfMemoryError. It worked with 1 MIllion digits tho. I save the String as a char[] array. Is it possible to somehow stream the .txt when i cycle through the whole array? I simply need a way to have access to all the 1 Billion digits as an array.

like image 408
Steakie Avatar asked Aug 04 '26 04:08

Steakie


1 Answers

There is BufferedInputStream since java 1 or FileReader with

public int read(char cbuf[], int offset, int length) throws IOException 

I suggest you start from there

like image 93
Pavel Niedoba Avatar answered Aug 06 '26 17:08

Pavel Niedoba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!