|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cleancode.util.FilePlus
public final class FilePlus
Convenience methods for file handling.
Field Summary | |
---|---|
static String |
VERSION
Current version of this class. |
Method Summary | |
---|---|
static String |
getPath(String fname)
Returns just the path portion of a file name. |
static boolean |
newer(File srcfile,
File destfile)
Determines if a source file, or any file in a source directory, is newer than a destination file. |
static boolean |
newer(File srcfile,
File destfile,
FilenameFilter filter)
Determines if a source file, or any file in a source directory, is newer than a destination file. |
static boolean |
newer(String srcfileName,
File destfile,
FilenameFilter filter)
Determines if a file or directory of the specified name, is newer than a destination file. |
static String |
readFile(BufferedReader reader)
Returns the contents of the BufferedReader as a String . |
static String |
readFile(InputStream stream)
Returns the contents of the InputStream as a String . |
static String |
readFile(String fname)
Returns the contents of the named file as a String . |
static String[] |
readFileAsArray(BufferedReader reader)
Returns the contents of the BufferedReader as a string array. |
static String[] |
readFileAsArray(InputStream stream)
Returns the contents of the InputStream as a string array. |
static String[] |
readFileAsArray(String fname)
Returns the contents of the named file as a String array. |
static String[] |
readFileAsArrayColumn(String fname,
int column)
Returns the contents of a single column in a field-delimited file as a String array. |
static String[] |
readFileAsArrayColumn(String fname,
String[][] filterList,
int column)
Returns the contents of a single column in a field-delimited file as a String array, filtering the input as it is read. |
static String[] |
readFileAsArrayColumn(String fname,
String[][] filterList,
int column,
String fieldSep)
Returns the contents of a single column in a field-delimited file as a String array, filtering the input as it is read. |
static boolean |
writeFile(String fname,
String text)
Write specified text to a file, overwriting the original, if any. |
static boolean |
writeFile(String fname,
String text,
String backupExt)
Write specified text to a file, backing up the original. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String VERSION
Method Detail |
---|
public static String readFile(String fname) throws IOException
String
.
fname
- name of the file to read
String
IOException
- if any problems reading the file.public static String readFile(InputStream stream) throws IOException
InputStream
as a String
.
stream
- input stream to read
String
IOException
- if any problems reading the file.public static String readFile(BufferedReader reader) throws IOException
BufferedReader
as a String
.
reader
- BufferedReader
to read
String
IOException
- if any problems reading the file.public static String[] readFileAsArray(String fname) throws IOException
String
array.
fname
- name of the file to read
IOException
- if any problems reading the file.public static String[] readFileAsArray(InputStream stream) throws IOException
InputStream
as a string array.
stream
- input stream to read
IOException
- if any problems reading the file.public static String[] readFileAsArray(BufferedReader reader) throws IOException
BufferedReader
as a string array.
reader
- BufferedReader
to read
IOException
- if any problems reading the file.public static String[] readFileAsArrayColumn(String fname, int column)
String
array.
fname
- name of the file to readcolumn
- column number (zero-based) to read from file
public static String[] readFileAsArrayColumn(String fname, String[][] filterList, int column)
String
array, filtering the input as it is read.
The filterList
contains 2-item sub-lists, where each
sub-list contains a regular expression to match, and a replacement
expression once matched.
fname
- name of the file to readfilterList
- list of search/replace terms to filter while readingcolumn
- column number (zero-based) to read from file
readFileAsArrayColumn(String, String[][], int, String)
public static String[] readFileAsArrayColumn(String fname, String[][] filterList, int column, String fieldSep)
String
array, filtering the input as it is read.
The filterList
contains 2-item sub-lists, where each
sub-list contains a regular expression to match, and a replacement
expression once matched.
One application of this is to remove sensitive data.
Another is for comparing files where, for example, datestamps
in the file will always differ, but are not significant.
Say for example there is a line "start time: Sat Dec 25 2:15pm"
where the actual date and time will vary. Specifying a sublist
of { "(start time:).*", "$1" }
as one element in filterList
will remove the varying part of the text.
fname
- name of the file to readfilterList
- list of search/replace terms to filter while readingcolumn
- column number (zero-based) to read from filefieldSep
- field separator regular expression used in file
public static boolean writeFile(String fname, String text, String backupExt)
fname
- file nametext
- text to writebackupExt
- extension for backup copy of the file
public static boolean writeFile(String fname, String text)
fname
- file nametext
- text to write
public static String getPath(String fname)
fname
- file name
public static boolean newer(File srcfile, File destfile, FilenameFilter filter)
srcfile
- source file or directory to comparedestfile
- destination file to comparefilter
- selects a subset of files if srcfile is a directory
public static boolean newer(String srcfileName, File destfile, FilenameFilter filter)
srcfileName
- name of source file or directory to comparedestfile
- destination file to comparefilter
- selects a subset of files if srcfile is a directory
newer(File, File, FilenameFilter)
public static boolean newer(File srcfile, File destfile)
srcfile
- source file or directory to comparedestfile
- destination file to compare
newer(File, File, FilenameFilter)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
CleanCode Java Libraries | Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 |