类 FileUtils

java.lang.Object
com.alibaba.cloud.commons.io.FileUtils

public final class FileUtils extends Object
FileUtils. copy from apache commons-io.
作者:
theonefx
  • 方法详细资料

    • openInputStream

      public static FileInputStream openInputStream(File file) throws IOException
      Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).

      At the end of the method either the stream will be successfully opened, or an exception will have been thrown.

      An exception is thrown if the file 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 read.

      参数:
      file - the file to open for input, must not be null
      返回:
      a new FileInputStream for the specified file
      抛出:
      FileNotFoundException - if the file does not exist
      IOException - if the file object is a directory
      IOException - if the file cannot be read
      从以下版本开始:
      1.3
    • readFileToString

      public static String readFileToString(File file, Charset encoding) throws IOException
      Reads the contents of a file into a String. The file is always closed.
      参数:
      file - the file to read, must not be null
      encoding - the encoding to use, null means platform default
      返回:
      the file contents, never null
      抛出:
      IOException - in case of an I/O error
    • readFileToString

      public static String readFileToString(File file, String encoding) throws IOException
      Reads the contents of a file into a String. The file is always closed.
      参数:
      file - the file to read, must not be null
      encoding - the encoding to use, null means platform default
      返回:
      the file contents, never null
      抛出:
      IOException - in case of an I/O error
      UnsupportedCharsetException - thrown instead of .UnsupportedEncodingException in version 2.2 if the encoding is not supported.
    • readFileToString

      @Deprecated public static String readFileToString(File file) throws IOException
      已过时。
      2.5 use readFileToString(File, String) instead (and specify the appropriate encoding)
      Reads the contents of a file into a String using the default encoding for the VM. 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