@Immutable public final class SimpleFileIO extends Object
FileOperations class or the instance based
FileOperationManager class.| Modifier and Type | Method and Description |
|---|---|
static byte[] |
getAllFileBytes(File aFile)
Get the content of the file as a byte array.
|
static byte[] |
getAllFileBytes(Path aPath) |
static ICommonsList<String> |
getAllFileLines(File aFile,
Charset aCharset)
Get the content of the passed file as a list of lines, whereas each line
does not contain a separator.
|
static String |
getFileAsString(File aFile,
Charset aCharset)
Get the content of the passed file as a string using the system line
separator.
|
static List<String> |
readAllLines(Path aPath,
Charset aCharset)
Read all lines from a file.
|
static void |
readFileLines(File aFile,
Charset aCharset,
Consumer<? super String> aConsumer)
Get the content of the passed file as a list of lines, whereas each line
does not contain a separator.
|
static void |
readFileLines(File aFile,
Charset aCharset,
List<String> aTargetList)
Get the content of the passed file as a list of lines, whereas each line
does not contain a separator.
|
static ESuccess |
writeFile(File aFile,
byte[] aContent) |
static ESuccess |
writeFile(File aFile,
byte[] aContent,
int nOffset,
int nLength) |
static ESuccess |
writeFile(File aFile,
String sContent,
Charset aCharset) |
@Nullable public static byte[] getAllFileBytes(@Nullable File aFile)
aFile - The file to read. May be null.null if the passed file is null or if the
passed file does not exist.public static List<String> readAllLines(@Nonnull Path aPath, @Nonnull Charset aCharset) throws IOException
This method recognizes the following as line terminators:
\u000D followed by \u000A, CARRIAGE
RETURN followed by LINE FEED\u000A, LINE FEED\u000D, CARRIAGE RETURNAdditional Unicode line terminators may be recognized in future releases.
Note that this method is intended for simple cases where it is convenient to read all lines in a single operation. It is not intended for reading in large files.
aPath - the path to the fileaCharset - the charset to use for decodingList; whether the List is modifiable or not is implementation dependent and
therefore not specifiedIOException - if an I/O error occurs reading from the file or a malformed or
unmappable byte sequence is readSecurityException - In the case of the default provider, and a security manager is
installed, the checkRead
method is invoked to check read access to the file.@Nullable public static String getFileAsString(@Nullable File aFile, @Nonnull Charset aCharset)
aFile - The file to read. May be null.aCharset - The character set to use. May not be null.null if the file does not exist, the content
otherwise.@Nullable public static ICommonsList<String> getAllFileLines(@Nullable File aFile, @Nonnull Charset aCharset)
aFile - The file to read. May be null.aCharset - The character set to use. May not be null.null if the file does not exist, the content
otherwise.public static void readFileLines(@Nullable File aFile, @Nonnull Charset aCharset, @Nonnull List<String> aTargetList)
aFile - The file to read. May be null.aCharset - The character set to use. May not be null.aTargetList - The target list to be filled. May not be null.public static void readFileLines(@Nullable File aFile, @Nonnull Charset aCharset, @Nonnull Consumer<? super String> aConsumer)
aFile - The file to read. May be null.aCharset - The character set to use. May not be null.aConsumer - The consumer to be invoked for each line. May not be
null.@Nonnull public static ESuccess writeFile(@Nonnull File aFile, @Nonnull byte[] aContent, @Nonnegative int nOffset, @Nonnegative int nLength)
Copyright © 2014–2017 Philip Helger. All rights reserved.