How do I convert a java.io.File to a byte[]?

27 s
27

From JDK 7 you can use Files.readAllBytes(Path).

Example:

import java.io.File;
import java.nio.file.Files;

File file;
// ...(file is initialised)...
byte[] fileContent = Files.readAllBytes(file.toPath());

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *