|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.norconex.commons.lang.io.FileUtil
public final class FileUtil
Utility methods when dealing with files and directories.
Method Summary | |
---|---|
static File |
createDateDirs(File parentDir)
Creates (if not already existing) a series of directories reflecting the current date, up to the day unit, under a given parent directory. |
static File |
createDateDirs(File parentDir,
Date date)
Creates (if not already existing) a series of directories reflecting a date, up to the day unit, under a given parent directory. |
static File |
createDateTimeDirs(File parentDir)
Creates (if not already existing) a series of directories reflecting the current date and time, up to the seconds, under a given parent directory. |
static File |
createDateTimeDirs(File parentDir,
Date dateTime)
Creates (if not already existing) a series of directories reflecting a date and time, up to the seconds, under a given parent directory. |
static File |
createDirsForFile(File file)
Create all parent directories for a file if they do not exists. |
static int |
deleteEmptyDirs(File parentDir)
Deletes all directories that are empty from a given parent directory. |
static void |
deleteFile(File file)
Deletes a file or a directory recursively. |
static String[] |
head(File file,
int numberOfLinesToRead)
Returns the specified number of lines starting from the beginning of a text file. |
static String[] |
head(File file,
String encoding,
int numberOfLinesToRead)
Returns the specified number of lines starting from the beginning of a text file, using the given encoding. |
static String[] |
head(File file,
String encoding,
int numberOfLinesToRead,
boolean stripBlankLines)
Returns the specified number of lines starting from the beginning of a text file, using the given encoding. |
static String[] |
head(File file,
String encoding,
int numberOfLinesToRead,
boolean stripBlankLines,
IInputStreamFilter filter)
Returns the specified number of lines starting from the beginning of a text file, using the given encoding. |
static void |
moveFile(File sourceFile,
File targetFile)
Moves a file to a new file location. |
static void |
moveFileToDir(File sourceFile,
File targetDir)
Moves a file to a directory. |
static String[] |
tail(File file,
int numberOfLinesToRead)
Returns the specified number of lines starting from the end of a text file. |
static String[] |
tail(File file,
String encoding,
int numberOfLinesToRead)
Returns the specified number of lines starting from the end of a text file. |
static String[] |
tail(File file,
String encoding,
int numberOfLinesToRead,
boolean stripBlankLines)
Returns the specified number of lines starting from the end of a text file. |
static String[] |
tail(File file,
String encoding,
int numberOfLinesToRead,
boolean stripBlankLines,
IInputStreamFilter filter)
Returns the specified number of lines starting from the end of a text file. |
static void |
visitAllDirs(File dir,
IFileVisitor visitor)
Visits only directories under a directory. |
static void |
visitAllDirsAndFiles(File dir,
IFileVisitor visitor)
Visits all files and directories under a directory. |
static void |
visitAllDirsAndFiles(File dir,
IFileVisitor visitor,
FileFilter filter)
Visits all files and directories under a directory. |
static void |
visitAllFiles(File dir,
IFileVisitor visitor)
Visits all files (and only files) under a directory, including sub-directories. |
static void |
visitAllFiles(File dir,
IFileVisitor visitor,
FileFilter filter)
Visits all files (and only files) under a directory, including sub-directories. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void moveFileToDir(File sourceFile, File targetDir) throws IOException
moveFile(File, File)
:
sourceFile
- source file to movetargetDir
- target destination
IOException
- cannot move file.public static void moveFile(File sourceFile, File targetFile) throws IOException
File.renameTo(File)
method in such that:
sourceFile
- source file to movetargetFile
- target destination
IOException
- cannot move file.public static void deleteFile(File file) throws IOException
null
or does not exist, nothing happens.
file
- file or directory to delete
IOException
- cannot delete file.public static int deleteEmptyDirs(File parentDir)
parentDir
- the directory where to start looking for empty
directories
public static File createDirsForFile(File file) throws IOException
file
- the file to create parent directories for
IOException
- if somethign went wrong creating the parent
directoriespublic static void visitAllDirsAndFiles(File dir, IFileVisitor visitor)
dir
- the directoryvisitor
- the visitorpublic static void visitAllDirsAndFiles(File dir, IFileVisitor visitor, FileFilter filter)
dir
- the directoryvisitor
- the visitorfilter
- an optional filter to restrict the files being visitedpublic static void visitAllDirs(File dir, IFileVisitor visitor)
dir
- the directoryvisitor
- the visitorpublic static void visitAllFiles(File dir, IFileVisitor visitor)
dir
- the directoryvisitor
- the visitorpublic static void visitAllFiles(File dir, IFileVisitor visitor, FileFilter filter)
dir
- the directoryvisitor
- the visitorfilter
- an optional filter to restrict the files being visitedpublic static String[] head(File file, int numberOfLinesToRead) throws IOException
file
- the file to read lines fromnumberOfLinesToRead
- the number of lines to read
IOException
public static String[] head(File file, String encoding, int numberOfLinesToRead) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to read
IOException
public static String[] head(File file, String encoding, int numberOfLinesToRead, boolean stripBlankLines) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to readstripBlankLines
- whether to return blank lines or not
IOException
public static String[] head(File file, String encoding, int numberOfLinesToRead, boolean stripBlankLines, IInputStreamFilter filter) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to readstripBlankLines
- whether to return blank lines or notfilter
- InputStream filter
IOException
public static String[] tail(File file, int numberOfLinesToRead) throws IOException
file
- the file to read lines fromnumberOfLinesToRead
- the number of lines to read
IOException
public static String[] tail(File file, String encoding, int numberOfLinesToRead) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to read
IOException
public static String[] tail(File file, String encoding, int numberOfLinesToRead, boolean stripBlankLines) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to readstripBlankLines
- whether to return blank lines or not
IOException
public static String[] tail(File file, String encoding, int numberOfLinesToRead, boolean stripBlankLines, IInputStreamFilter filter) throws IOException
file
- the file to read lines fromencoding
- the file encodingnumberOfLinesToRead
- the number of lines to readstripBlankLines
- whether to return blank lines or notfilter
- InputStream filter
IOException
public static File createDateDirs(File parentDir) throws IOException
/<parentDir>/2000/12/31/
parentDir
- the parent directory where to create date directories
IOException
- if the parent directory is not validpublic static File createDateDirs(File parentDir, Date date) throws IOException
/<parentDir>/2000/12/31/
parentDir
- the parent directory where to create date directoriesdate
- the date to create directories from
IOException
- if the parent directory is not validpublic static File createDateTimeDirs(File parentDir) throws IOException
/<parentDir>/2000/12/31/13/34/12/
parentDir
- the parent directory where to create date directories
IOException
- if the parent directory is not validpublic static File createDateTimeDirs(File parentDir, Date dateTime) throws IOException
/<parentDir>/2000/12/31/13/34/12/
parentDir
- the parent directory where to create date directoriesdateTime
- the date to create directories from
IOException
- if the parent directory is not valid
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |