public final class FileUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static int |
countLines(java.io.File file) |
static int |
countLines(java.io.File file,
java.lang.String excludePrefix) |
static int |
countLines(java.lang.String filename) |
static <T> java.util.List<T> |
deserializeFromFile(java.io.File file)
Deserializes a list of Objects from the given file
|
static void |
serializeToFile(java.util.Collection objects,
java.io.File file)
Serializes a Collection of Objects to a given file
|
static void |
writeDelimitedFile(java.lang.String[][] headers,
java.lang.String[][] data,
java.lang.String delimiter,
java.io.File file) |
static void |
writeFile(java.lang.String contents,
java.io.File file) |
static void |
writeFile(java.lang.String contents,
java.io.File file,
boolean append) |
public static int countLines(java.lang.String filename) throws java.io.IOException
filename
- the name of the filejava.io.IOException
- in case the file can not be readpublic static int countLines(java.io.File file) throws java.io.IOException
file
- the filejava.io.IOException
- in case the file can not be readpublic static int countLines(java.io.File file, java.lang.String excludePrefix) throws java.io.IOException
file
- the fileexcludePrefix
- lines are excluded from the count if they start with this stringjava.io.IOException
- in case the file can not be readpublic static void writeDelimitedFile(java.lang.String[][] headers, java.lang.String[][] data, java.lang.String delimiter, java.io.File file) throws java.io.IOException
headers
- any headers to write firstdata
- the datadelimiter
- the delimiterfile
- the file to write tojava.io.IOException
- in case of an exceptionpublic static void writeFile(java.lang.String contents, java.io.File file) throws java.io.IOException
contents
- the contents to write to the file, overwriting the contentsfile
- the filejava.io.IOException
- in case of an exceptionpublic static void writeFile(java.lang.String contents, java.io.File file, boolean append) throws java.io.IOException
contents
- the contents to write to the filefile
- the fileappend
- if true the contents are appended, otherwise overwrittenjava.io.IOException
- in case of an exceptionpublic static <T> java.util.List<T> deserializeFromFile(java.io.File file) throws java.io.IOException, java.lang.ClassNotFoundException
T
- the type of objects to read from the filefile
- the filejava.io.IOException
- in case the file can not be readjava.lang.ClassNotFoundException
- in case the deserialized class is not foundpublic static void serializeToFile(java.util.Collection objects, java.io.File file) throws java.io.IOException
objects
- the objects to serializefile
- the filejava.io.IOException
- in case the file can not be written