Java 8 – Reading a file as String

There are a lot of examples how to read a file content in Java 8.
The most common one is

 However, you can receive different results for the same file on different operation systems! 

Use always a charset with String to Byte array transformations and vice versa to achieve a cross-platform identical output from this code section:

If you have found a spelling error, please, notify us by selecting that text and pressing Ctrl+Enter.

You may also like...

Spelling error report

The following text will be sent to our editors: