| Modifier and Type | Method and Description |
|---|---|
static FileInputStream |
openInputStream(File file)
Opens a
FileInputStream for the specified file, providing better
error messages than simply calling new FileInputStream(file). |
static String |
readFileToString(File file)
Deprecated.
2.5 use
readFileToString(File, String) instead (and specify
the appropriate encoding) |
static String |
readFileToString(File file,
Charset encoding)
Reads the contents of a file into a String.
|
static String |
readFileToString(File file,
String encoding)
Reads the contents of a file into a String.
|
public static FileInputStream openInputStream(File file) throws IOException
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 nullFileInputStream for the specified fileFileNotFoundException - if the file does not existIOException - if the file object is a directoryIOException - if the file cannot be readpublic static String readFileToString(File file, Charset encoding) throws IOException
file - the file to read, must not be nullencoding - the encoding to use, null means platform defaultnullIOException - in case of an I/O errorpublic static String readFileToString(File file, String encoding) throws IOException
file - the file to read, must not be nullencoding - the encoding to use, null means platform defaultnullIOException - in case of an I/O errorUnsupportedCharsetException - thrown instead of
.UnsupportedEncodingException in version 2.2 if the encoding is not
supported.@Deprecated public static String readFileToString(File file) throws IOException
readFileToString(File, String) instead (and specify
the appropriate encoding)file - the file to read, must not be nullnullIOException - in case of an I/O errorCopyright © 2021 Pivotal Software, Inc.. All rights reserved.