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());
Related Contents:
- How do I create a Java string from the contents of a file?
- How do I create a file and write to it?
- How do I check if a file exists in Java?
- How to append text to an existing file in Java?
- Delete directories recursively in Java
- How to create a temporary directory/folder in Java?
- Scanner vs. BufferedReader
- Read/Write String from/to a File in Android
- Delete all files in directory (but not directory) – one liner solution
- getResourceAsStream returns null
- Java FileOutputStream Create File if not exists
- How to write a UTF-8 file with Java?
- getResourceAsStream() vs FileInputStream
- How do you determine the ideal buffer size when using FileInputStream?
- How to save a BufferedImage as a File
- How to delete a folder with files using Java
- Does Java have a path joining method? [duplicate]
- Why doesn’t java.io.File have a close method?
- Is it necessary to close each nested OutputStream and Writer separately?
- How can I lock a file using java (if possible)
- Create a File object in memory from a string in Java
- How to read a specific line using the specific line number from a file in Java?
- How to add a new line of text to an existing file in Java? [duplicate]
- Reliable File.renameTo() alternative on Windows?
- File.exists() returns false when file exists
- List all files from a directory recursively with Java
- GZIPInputStream reading line by line
- Create a file from a ByteArrayOutputStream
- 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?
- How to read text file from classpath in Java?
- Write a file in UTF-8 using FileWriter (Java)?
- Copy entire directory contents to another directory? [duplicate]
- Java difference between FileWriter and BufferedWriter
- java.io.FileNotFoundException: the system cannot find the file specified
- How to check if a directory is empty in Java
- Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream?
- How to read a file from jar in Java?
- Reading a .txt file using Scanner class in Java
- Whole text file to a String in Java
- How to check if a given path is possible child of another path?
- How to convert String to Reader in java
- How do relative file paths work in Eclipse?
- Check if file is already open
- Does groovy have an easy way to get a filename without the extension?
- Java Files.write NoSuchFileException
- At what point does wrapping a FileOutputStream with a BufferedOutputStream make sense, in terms of performance?
- Is this the best way to rewrite the content of a file in Java?
- Java – get the newest file in a directory?
- Open in Java(TM) Platform SE binary