Hacker News new | ask | show | jobs
by brokenmachine 3403 days ago
This is what always bugged me about java. I'm only just above a beginner, but it seems to me that in 2017 you shouldn't have to write so much crap just to read from a file.

BufferedReader, FileReader, blah blah blah

http://www.mkyong.com/java/how-to-read-file-from-java-buffer...

Maybe there's a good reason to make it this difficult, if so I'm not aware of it.

1 comments

There is - but there is no good reason to not have good naming plus also a simple wrapper to do the most common cases. That the IO framework is very general is good, but that you need tons of boilerplate for a common scenario is bad. C#

  var txt = File.ReadAllText("file.txt");
This is exactly the abstraction you want if you want to read a (whole) text file. The point of abstractions is to pick the right one. For IO it's likely best to have many layers of abstraction so you can choose the simple top level function or use a more complex one when needed.

I'm sure there is something similar in Java these days too. Would be a huge mistake to not have simple IO helpers to the std library.

Something like that, though the method to read a whole file into a single string seems absent for some strange reason.