How do I convert a java.io.File
to a byte[]
?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Not only does the following way convert a java.io.File to a byte[], I also found it to be the fastest way to read in a file, when testing many different Java file reading methods against each other:
java.nio.file.Files.readAllBytes()
As someone said, Apache Commons File Utils might have what you are looking for
Example use (
Program.java
):Since JDK 7 - one liner:
No external dependencies needed.
I belive this is the easiest way: