Java IO & NIO Java Java API
java.nio.file.Files
public static byte[] readAllBytes(Path path) throws IOException
Reads all the bytes from a file.
path
package com.logicbig.example.files;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;public class ReadAllBytesExample { public static void main(String... args) throws IOException { Path path = Files.createTempFile("test-file", ".txt"); //write Files.write(path, "Some test data..".getBytes()); //read byte[] bytes = Files.readAllBytes(path); System.out.println(new String(bytes)); }}
Some test data..