public class FileUtils extends Object
org.apache.commons.io.FileUtils| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static File |
getTempDirectory() |
static FileOutputStream |
openOutputStream(File file,
boolean append)
Opens a
FileOutputStream for the specified file, checking and
creating the parent directory if it does not exist. |
static byte[] |
readFileToByteArray(File file)
Reads the contents of a file into a byte array.
|
static void |
writeByteArrayToFile(File file,
byte[] data)
Writes a byte array to a file creating the file if it does not exist.
|
static void |
writeByteArrayToFile(File file,
byte[] data,
boolean append)
Writes a byte array to a file creating the file if it does not exist.
|
static void |
writeByteArrayToFile(File file,
byte[] data,
int off,
int len)
Writes
len bytes from the specified byte array starting at offset
off to a file, creating the file if it does not exist. |
static void |
writeByteArrayToFile(File file,
byte[] data,
int off,
int len,
boolean append)
Writes
len bytes from the specified byte array starting at offset
off to a file, creating the file if it does not exist. |
public static File getTempDirectory()
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
NOTE: As from v1.3, the parent directories of the file will be created if they do not exist.
file - the file to write todata - the content to write to the fileIOException - in case of an I/O errorpublic static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException
file - the file to write todata - the content to write to the fileappend - if true, then bytes will be added to the end of the
file rather than overwritingIOException - in case of an I/O errorpublic static void writeByteArrayToFile(File file, byte[] data, int off, int len) throws IOException
len bytes from the specified byte array starting at offset
off to a file, creating the file if it does not exist.file - the file to write todata - the content to write to the fileoff - the start offset in the datalen - the number of bytes to writeIOException - in case of an I/O errorpublic static void writeByteArrayToFile(File file, byte[] data, int off, int len, boolean append) throws IOException
len bytes from the specified byte array starting at offset
off to a file, creating the file if it does not exist.file - the file to write todata - the content to write to the fileoff - the start offset in the datalen - the number of bytes to writeappend - if true, then bytes will be added to the end of the
file rather than overwritingIOException - in case of an I/O errorpublic static FileOutputStream openOutputStream(File file, boolean append) throws IOException
FileOutputStream for the specified file, checking and
creating the parent directory if it does not exist.
At the end of the method either the stream will be successfully opened, or an exception will have been thrown.
The parent directory will be created if it does not exist. The file will be created if it does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be written to. An exception is thrown if the parent directory cannot be created.
file - the file to open for output, must not be nullappend - if true, then bytes will be added to the end of the
file rather than overwritingFileOutputStream for the specified fileIOException - if the file object is a directoryIOException - if the file cannot be written toIOException - if a parent directory needs creating but that failspublic static byte[] readFileToByteArray(File file) throws IOException
file - the file to read, must not be nullnullIOException - in case of an I/O errorCopyright © 2021. All rights reserved.