Does Java has a one line instruction to read to a text file, like what C# has?
I mean, is there something equivalent to this in Java?:
String data = System.IO.File.ReadAllText("path to file");
If not… what is the ‘optimal way’ to do this…?
Edit:
I prefer a way within Java standard libraries… I can not use 3rd party libraries..
Java 11 adds support for this use-case with Files.readString, sample code:
Before Java 11, typical approach with standard libraries would be something like this:
Notes: