|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object comirva.util.FileUtils
public class FileUtils
This class implements simple utilities related to file processing.
Nested Class Summary | |
---|---|
static class |
FileUtils.TextFileIterator
Iterates over the lines of a text file without storing the whole contents of the text file in RAM (only one line at a time is kept in RAM, except for object reference / garbage collection issues) |
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | ||
---|---|---|
static File[] |
getAllFilesRecursively(File[] files,
FileFilter filter)
Creates and returns a File[] containing all files in all subdirectories of the files given as argument files . |
|
static String |
getFileContent(File textFile)
Fetch the entire content of a text file and return it in a String. |
|
static List<String> |
getFilesInDir(String dirname,
String filter,
boolean isRecursive)
Get the names of the files in the specified directory. |
|
static String |
insertContent(String page,
String anchor,
String content)
|
|
static Object |
load(String filename)
Reads the serialized object from the file. |
|
static boolean |
mkdir(File dir)
|
|
static float[] |
readFloatFile(File f,
int no_floats)
Reads up to no_floats floats from a file f . |
|
static ArrayList<String> |
readTextFile(File textfile)
Read the specified text file. |
|
static String |
removeUnwantedChars(String str)
Removes all non-digit and non-letter characters from a string and returns it in lower case. |
|
static boolean |
save(Serializable object,
String filename)
Serializes the given object to the given filename. |
|
static void |
setFileContent(File textFile,
String content)
Change the contents of text file, overwriting any existing text. |
|
static void |
writeToFile(String outfilename,
Object[] data)
Writes a text file by calling for each object in data[] the toString() method, followed by a newline character. |
|
static
|
writeToTextFile(String outfilename,
HashMap<K,V> hm)
Writes all key-value pairs to a text file, each "line" taking the form "k:v", where k is key.toString() and v is value.toString(). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static String getFileContent(File textFile)
textFile
- is a file which already exists and can be readpublic static void setFileContent(File textFile, String content)
textFile
- is an existing file which can be written tocontent
- a String representing the content that is to be written to the filepublic static String insertContent(String page, String anchor, String content)
page
- the web page templateanchor
- the comment used in the template (which is replaced)content
- the content to be inserted instead of the anchor
public static String removeUnwantedChars(String str)
str
- the string to be processed
public static <K,V> void writeToTextFile(String outfilename, HashMap<K,V> hm)
K
- V
- outfilename
- hm
- public static void writeToFile(String outfilename, Object[] data)
outfilename
- data
- public static ArrayList<String> readTextFile(File textfile)
textfile
-
public static float[] readFloatFile(File f, int no_floats)
no_floats
floats from a file f
.
If more lines than no_floats are contained in the file, an array index
out of bounds exception is thrown. If less lines are contained, the last
idcs of the returned array are zero.
public static boolean mkdir(File dir)
public static boolean save(Serializable object, String filename)
object
- filename
-
public static Object load(String filename)
filename
- the name of the file containing the serialized object data.
public static List<String> getFilesInDir(String dirname, String filter, boolean isRecursive)
dirname
- the name of the directoryfilter
- a regular expression, e.g., ".*?\\.txt"isRecursive
- if true, then this function also reports files in
sub-directories below the specified directory, otherwise only files in the specified
directory.
public static File[] getAllFilesRecursively(File[] files, FileFilter filter)
files
. Furthermore, a file filter can be
specified.
files
- the files and directories which are to be searchedfilter
- a FileFilter to be applied to the search
files
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |