Why are there no simple IO-utils in the JDK to read an entire file into a String?

In the comments to my answer about reading an entire file into memory withscala.io.Source

, I argued that the reason there is no integer-integer file in the -String Method in Java is that it (of course) doesn't scale with respect to how large file and how much heap you have.

However, I think everyone has some method like:

String contents = IOUtil.readFile(f, "utf-8");


And the implementation of the method is just a few lines of code. Why didn't they just add this to the JDK in the first place? Is this my (scalability) reason or is there some other reason it was omitted?


source to share

2 answers

Since files can be of arbitrary size and it is just bad programming practice to do this kind of thing without a lot of checks and balances to make sure you don't knock the VM left and right.



I think your own answer is correct. What if your file is 1 GB long?



All Articles