类 FileUtils
java.lang.Object
com.alibaba.cloud.commons.io.FileUtils
FileUtils. copy from apache commons-io.
- 作者:
- theonefx
-
方法概要
修饰符和类型方法说明static FileInputStreamopenInputStream(File file) Opens aFileInputStreamfor the specified file, providing better error messages than simply callingnew FileInputStream(file).static StringreadFileToString(File file) 已过时。static StringreadFileToString(File file, String encoding) Reads the contents of a file into a String.static StringreadFileToString(File file, Charset encoding) Reads the contents of a file into a String.
-
方法详细资料
-
openInputStream
Opens aFileInputStreamfor the specified file, providing better error messages than simply callingnew 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 benull- 返回:
- a new
FileInputStreamfor the specified file - 抛出:
FileNotFoundException- if the file does not existIOException- if the file object is a directoryIOException- if the file cannot be read- 从以下版本开始:
- 1.3
-
readFileToString
Reads the contents of a file into a String. The file is always closed.- 参数:
file- the file to read, must not benullencoding- the encoding to use,nullmeans platform default- 返回:
- the file contents, never
null - 抛出:
IOException- in case of an I/O error
-
readFileToString
Reads the contents of a file into a String. The file is always closed.- 参数:
file- the file to read, must not benullencoding- the encoding to use,nullmeans platform default- 返回:
- the file contents, never
null - 抛出:
IOException- in case of an I/O errorUnsupportedCharsetException- thrown instead of.UnsupportedEncodingExceptionin version 2.2 if the encoding is not supported.
-
readFileToString
已过时。2.5 usereadFileToString(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 benull- 返回:
- the file contents, never
null - 抛出:
IOException- in case of an I/O error
-
readFileToString(File, String)instead (and specify the appropriate encoding)