Read all file content to a byte array : File Operation « JDK 7 « Java
- Java
- JDK 7
- File Operation
Read all file content to a byte array
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test {
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);
}
}
}
Related examples in the same category