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());
More Related Contents:
- Writing object in text file
- How to move elements of Java ArrayList to file in java [closed]
- How to append text to an existing file in Java?
- Scanner vs. BufferedReader
- How to read a specific line using the specific line number from a file in Java?
- How to write console output to a txt file
- Reliable File.renameTo() alternative on Windows?
- File Upload with Java (with progress bar)
- List all files from a directory recursively with Java
- How to add a new line of text to an existing file in Java? [duplicate]
- Java IOException “Too many open files”
- Getting the inputstream from a classpath resource (XML file)
- How do I use Java to read from a file that is actively being written to?
- Elegant way to read file into byte[] array in Java [duplicate]
- Check line for unprintable characters while reading text file
- Writing a file to sdcard
- Reset buffer with BufferedReader in Java?
- Java FileInputStream ObjectInputStream reaches end of file EOF
- Java: CSV File Easy Read/Write
- I/O concept flush vs sync
- File truncate operation in Java
- Why doesn’t java.io.File have a close method?
- Getting “java.nio.file.AccessDeniedException” when trying to write to a folder
- java IO to copy one File to another
- Does BufferedReader.ready() method ensure that readLine() method does not return NULL?
- Exception in thread “main” java.io.FileNotFoundException: Error
- Java reading a file different methods
- Does collect operation on Stream close the stream and underlying resources?
- Using reflection to change static final File.separatorChar for unit testing?
- Difference between Files#delete(Path) and File#delete()