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
1 2 3 4 5 6 7 |
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String content = new String(Files.readAllBytes(Paths.get("duke.java"))); } |
Use always a charset with String to Byte array transformations and vice versa...