类 FileUtils

java.lang.Object
com.alibaba.bytekit.utils.FileUtils

public class FileUtils extends Object
作者:
hengyunabc 2020-05-03
另请参阅:
  • 引用无效
    org.apache.commons.io.FileUtils
  • 构造器详细资料

    • FileUtils

      public FileUtils()
  • 方法详细资料

    • getTempDirectory

      public static File getTempDirectory()
    • writeByteArrayToFile

      public static void writeByteArrayToFile(File file, byte[] data) throws IOException
      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 to
      data - the content to write to the file
      抛出:
      IOException - in case of an I/O error
      从以下版本开始:
      1.1
    • writeByteArrayToFile

      public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException
      Writes a byte array to a file creating the file if it does not exist.
      参数:
      file - the file to write to
      data - the content to write to the file
      append - if true, 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
      Writes 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 to
      data - the content to write to the file
      off - the start offset in the data
      len - 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
      Writes 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 to
      data - the content to write to the file
      off - the start offset in the data
      len - the number of bytes to write
      append - if true, 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

      public static FileOutputStream openOutputStream(File file, boolean append) throws IOException
      Opens a 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 null
      append - if true, then bytes will be added to the end of the file rather than overwriting
      返回:
      a new FileOutputStream for the specified file
      抛出:
      IOException - if the file object is a directory
      IOException - if the file cannot be written to
      IOException - if a parent directory needs creating but that fails
      从以下版本开始:
      2.1
    • readFileToByteArray

      public static byte[] readFileToByteArray(File file) throws IOException
      Reads the contents of a file into a byte array. The file is always closed.
      参数:
      file - the file to read, must not be null
      返回:
      the file contents, never null
      抛出:
      IOException - in case of an I/O error
      从以下版本开始:
      1.1