Home > Java > javaTutorial > How to Convert a Java File to a byte[] Array?

How to Convert a Java File to a byte[] Array?

Barbara Streisand
Release: 2024-12-21 09:34:10
Original
868 people have browsed it

How to Convert a Java File to a byte[] Array?

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());
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template