类 FileUtils
java.lang.Object
com.alibaba.bytekit.utils.FileUtils
- 作者:
- hengyunabc 2020-05-03
- 另请参阅:
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static Filestatic FileOutputStreamopenOutputStream(File file, boolean append) Opens aFileOutputStreamfor 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 voidwriteByteArrayToFile(File file, byte[] data) Writes a byte array to a file creating the file if it does not exist.static voidwriteByteArrayToFile(File file, byte[] data, boolean append) Writes a byte array to a file creating the file if it does not exist.static voidwriteByteArrayToFile(File file, byte[] data, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto a file, creating the file if it does not exist.static voidwriteByteArrayToFile(File file, byte[] data, int off, int len, boolean append) Writeslenbytes from the specified byte array starting at offsetoffto a file, creating the file if it does not exist.
-
构造器详细资料
-
FileUtils
public FileUtils()
-
-
方法详细资料
-
getTempDirectory
-
writeByteArrayToFile
Writes a byte array to a file creating the file if it does not exist.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 file- 抛出:
IOException- in case of an I/O error- 从以下版本开始:
- 1.1
-
writeByteArrayToFile
Writes a byte array to a file creating the file if it does not exist.- 参数:
file- the file to write todata- the content to write to the fileappend- iftrue, then bytes will be added to the end of the file rather than overwriting- 抛出:
IOException- in case of an I/O error- 从以下版本开始:
- 2.1
-
writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data, int off, int len) throws IOException Writeslenbytes from the specified byte array starting at offsetoffto 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 write- 抛出:
IOException- in case of an I/O error- 从以下版本开始:
- 2.5
-
writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data, int off, int len, boolean append) throws IOException Writeslenbytes from the specified byte array starting at offsetoffto 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- iftrue, then bytes will be added to the end of the file rather than overwriting- 抛出:
IOException- in case of an I/O error- 从以下版本开始:
- 2.5
-
openOutputStream
Opens aFileOutputStreamfor 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 benullappend- iftrue, then bytes will be added to the end of the file rather than overwriting- 返回:
- a new
FileOutputStreamfor the specified file - 抛出:
IOException- if the file object is a directoryIOException- if the file cannot be written toIOException- if a parent directory needs creating but that fails- 从以下版本开始:
- 2.1
-
readFileToByteArray
Reads the contents of a file into a byte array. The file is always closed.- 参数:
file- the file to read, must not benull- 返回:
- the file contents, never
null - 抛出:
IOException- in case of an I/O error- 从以下版本开始:
- 1.1
-