File to byte in Java[]
Question: How to convert java.io.File to byte []?
Answer:
Starting 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());
The above is the detailed content of How to Convert a Java File to a byte[] Array?. For more information, please follow other related articles on the PHP Chinese website!