Package com.alibaba.cloud.commons.io
Class FileUtils
java.lang.Object
com.alibaba.cloud.commons.io.FileUtils
FileUtils. copy from apache commons-io.
- Author:
- theonefx
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileInputStreamopenInputStream(File file) Opens aFileInputStreamfor the specified file, providing better error messages than simply callingnew FileInputStream(file).static StringreadFileToString(File file) Deprecated.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.
-
Method Details
-
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.
- Parameters:
file- the file to open for input, must not benull- Returns:
- a new
FileInputStreamfor the specified file - Throws:
FileNotFoundException- if the file does not existIOException- if the file object is a directoryIOException- if the file cannot be read- Since:
- 1.3
-
readFileToString
Reads the contents of a file into a String. The file is always closed.- Parameters:
file- the file to read, must not benullencoding- the encoding to use,nullmeans platform default- Returns:
- the file contents, never
null - Throws:
IOException- in case of an I/O error
-
readFileToString
Reads the contents of a file into a String. The file is always closed.- Parameters:
file- the file to read, must not benullencoding- the encoding to use,nullmeans platform default- Returns:
- the file contents, never
null - Throws:
IOException- in case of an I/O errorUnsupportedCharsetException- thrown instead of.UnsupportedEncodingExceptionin version 2.2 if the encoding is not supported.
-
readFileToString
Deprecated.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.- Parameters:
file- the file to read, must not benull- Returns:
- the file contents, never
null - Throws:
IOException- in case of an I/O error
-
readFileToString(File, String)instead (and specify the appropriate encoding)