Read all file content to a byte array with java.nio.file.Files in Java
Description
The following code shows how to read all file content to a byte array with java.nio.file.Files.
Example
/* w w w . j a v a 2 s. c o m*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws IOException {
Path path = Paths.get("/users.txt");
byte[] contents = Files.readAllBytes(path);
for (byte b : contents) {
System.out.print((char) b);
}
}
}