What is simplest way to read a file into String?
Using Scanner Class
The following Java code will read an entire file into the String.
Note : useDelimiter("\\Z") is set the delimiter to the end of the file
Java NIO (New IO) is an alternative IO API for Java (from Java 1.4), meaning alternative to the standard Java IO and Java Networking API's.
Stream Oriented vs. Buffer Oriented
Java IO being stream oriented means that you read one or more bytes at a time, from a stream. What you do with the read bytes is up to you. Java NIO's buffer oriented approach is slightly different. Data is read into a buffer from which it is later processed.
The following Java code is a compact, robust idiom for Java 7 , wrapped up in a utility method.