|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.util.TextTools
Class TextTools is a special purpose class for
reading and writing data on local disk files.
See also:
TextFileIO
in package edu.neu.ccs.gui
| Constructor Summary | |
private |
TextTools()
Prevent instantiation. |
| Method Summary | |
static void |
copyTextFile(String oldPath,
String newPath)
Copies a text file from one place to another. |
static String[] |
extractNonEmptyLines(String data)
Finds and trims the lines in the given data and returns the trimmed lines that are non-empty into a string array. |
static String |
makePath(String directory,
String filename)
Makes a file path from the directory name and file name adding a path separator character if necessary. |
static String[] |
readFileNames(String directory,
String filelist)
Returns the file names in the filelist text file located in the given directory. |
static String[] |
readNonEmptyLines(String path)
Reads and trims the lines in the given file and returns the trimmed lines that are non-empty into a string array. |
static String |
readTextFile(String path)
Reads a text file and returns all of its data as a string. |
static void |
writeTextFile(String path,
String data)
Writes a text file whose contents will be the given data. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
private TextTools()
| Method Detail |
public static String readTextFile(String path)
Reads a text file and returns all of its data as a string.
Assumes that the entire file may be read into memory at once.
Throws RuntimeException if an error occurs.
path - the text file path on the local file system
public static void writeTextFile(String path,
String data)
Writes a text file whose contents will be the given data.
Throws RuntimeException if an error occurs.
path - the text file path on the local file systemdata - the text file contents as a string
public static void copyTextFile(String oldPath,
String newPath)
Copies a text file from one place to another.
Assumes that the entire file can be read into memory at once.
oldPath - the source text file path on the local file systemnewPath - the target text file path on the local file systempublic static String[] readNonEmptyLines(String path)
Reads and trims the lines in the given file and returns the trimmed lines that are non-empty into a string array.
Throws RuntimeException if an error occurs.
Assumes that the entire file can be read into memory at once.
path - the text file path on the local file system
public static String[] extractNonEmptyLines(String data)
Finds and trims the lines in the given data and returns the trimmed lines that are non-empty into a string array.
data - the string data to convert into an array of lines
public static String[] readFileNames(String directory,
String filelist)
Returns the file names in the filelist text file located in the given directory.
Assumes that filelist is the name of a text file in the same directory as the files listed within it.
The filelist text file should contain one name per line. Blank lines are permitted as separator lines.
Appends the file separatory character to the given directory string if necessary.
If an error occurs, returns a zero-length string array rather than throw an exception.
directory - the directory with the files and the file listfilelist - the text file with the list of file names
public static String makePath(String directory,
String filename)
Makes a file path from the directory name and file name adding a path separator character if necessary.
Throws RuntimeException if an error occurs.
directory - the directory stringfilename - the file name string
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||