public class FileOps
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileOps.FileLineIterator
Enables iterating line wise over a text file.
|
Constructor and Description |
---|
FileOps() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
fileContentToString(java.io.File file)
Reads the whole content of the given (text) file and returns it as a string.
|
static java.lang.String |
fileContentToString(java.lang.String filename)
Reads the whole content of the (text) file with the given filename.
|
static java.util.LinkedList<java.lang.String> |
fileLinesToList(java.io.File file)
Creates and returns a list containing the lines of the given (text) file.
|
static java.util.LinkedList<java.lang.String> |
fileLinesToList(java.lang.String filename)
Creates and returns a list containing the lines of the file with the given filename.
|
static java.lang.Iterable<java.lang.String> |
iterateFileLines(java.io.File file)
Enables iterating over the lines of the given (text) file.
|
static java.lang.Iterable<java.lang.String> |
iterateFileLines(java.lang.String filename)
Enables iterating over the lines of the (text) file with the given filename.
|
static java.lang.Iterable<java.io.File> |
iterateFiles(java.io.File directory,
boolean recursive,
boolean addDirectories)
Enables iterating over all files of the given directory.
|
static java.lang.Iterable<java.io.File> |
iterateFiles(java.io.File directory,
boolean recursive,
boolean addDirectories,
java.lang.String[] extensions)
Enables iterating over all or some files of the given directory.
|
static void |
listFiles(java.util.LinkedList<java.io.File> targetList,
java.io.File directory,
boolean recursive,
boolean addDirectories,
java.lang.String[] extensions)
Adds all or some files of the given directory with the given extensions to the
given list.
|
static java.util.LinkedList<java.io.File> |
listFiles(java.lang.String directory,
boolean recursive,
boolean addDirectories,
java.lang.String[] extensions)
Lists all or some files of the given directory.
|
static void |
writeStringToFile(java.io.File file,
java.lang.String string)
Creates a whole text file with the given string as content.
|
static void |
writeStringToFile(java.lang.String filename,
java.lang.String string)
Creates a whole text file with the given string as content.
|
static java.io.BufferedWriter |
writeToFile(java.io.File file)
Initializes and returns a buffered writer to write into the given file.
|
public static void listFiles(java.util.LinkedList<java.io.File> targetList, java.io.File directory, boolean recursive, boolean addDirectories, java.lang.String[] extensions)
targetList
- the list in which to add the files.directory
- the file system directory containing the files to add.recursive
- if true, then the files of all sub directories will be added
as well.addDirectories
- if true, then also directories will be added as a file in the target list.extensions
- the file extensions. If null, then all files will be added.
Otherwise, only files with extensions contained in the array
will be added (non-case-sensitive).public static java.util.LinkedList<java.io.File> listFiles(java.lang.String directory, boolean recursive, boolean addDirectories, java.lang.String[] extensions)
directory
- the directory containing the files to list.recursive
- if true, then the files of all sub directories will be added as well.addDirectories
- if true, then also directories will be added as a file in the list.extensions
- the file extensions. If null, then all files will be added. Otherwise, only files with
extensions contained in the array will be added (non-case-sensitive).public static java.lang.Iterable<java.io.File> iterateFiles(java.io.File directory, boolean recursive, boolean addDirectories, java.lang.String[] extensions)
directory
- the directory containing the files to iterate over.recursive
- if true, then the iteration includes the files of the sub directory.addDirectories
- if true, then also sub directories will be iterated as a file.extensions
- the file extensions. Only files with extensions which are contained in the given array
are part of the iteration.public static java.lang.Iterable<java.io.File> iterateFiles(java.io.File directory, boolean recursive, boolean addDirectories)
directory
- the directory containing the files to iterate over.recursive
- if true, then the iteration includes the files of the sub directory.addDirectories
- if true, then also sub directories will be iterated as a file.public static java.lang.String fileContentToString(java.io.File file) throws java.io.IOException
file
- the file to read.java.io.IOException
- if reading of the given file fails.public static java.lang.String fileContentToString(java.lang.String filename) throws java.io.IOException
filename
- the relative or absolute filename.java.io.IOException
- if reading the file fails.public static void writeStringToFile(java.io.File file, java.lang.String string) throws java.io.IOException
file
- the file to write to.string
- the content of the file.java.io.IOException
- if creating the file fails.public static void writeStringToFile(java.lang.String filename, java.lang.String string) throws java.io.IOException
filename
- the relative or absolute filename of the file to create.string
- the content of the file.java.io.IOException
- if creating the file fails.public static java.lang.Iterable<java.lang.String> iterateFileLines(java.io.File file)
file
- the file to iterate over.public static java.lang.Iterable<java.lang.String> iterateFileLines(java.lang.String filename)
filename
- the relative or absolute filename of the file.public static java.io.BufferedWriter writeToFile(java.io.File file) throws java.io.IOException
file
- the file to write to.java.io.IOException
- if creating the buffered writer fails.public static java.util.LinkedList<java.lang.String> fileLinesToList(java.io.File file)
file
- the file to read.public static java.util.LinkedList<java.lang.String> fileLinesToList(java.lang.String filename)
filename
- the relative or absolute path of the file with the given filename.