|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.cip4.jdflib.util.FileUtil
public class FileUtil
collection of helper routines to work with files
| Nested Class Summary | |
|---|---|
protected static class |
FileUtil.DirectoryFileFilter
simple file filter that lists all directories |
protected static class |
FileUtil.ExpressionFileFilter
simple file filter that lists all files that match a regular expression |
static class |
FileUtil.ExtensionFileFilter
Inner class *********************** UtilFileFilter |
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static File |
cleanDots(File file)
remove any internal "../" "./" and "//" from a url |
static File |
cleanURL(File f)
|
static boolean |
copyBytes(byte[] buf,
File toFile)
copy a buffer to the end of a file, creating it if necessary |
static boolean |
copyFile(File fromFile,
File toFile)
copy a file, unless fromFile and toFile are equal |
static File |
copyFileToDir(File fromFile,
File toDir)
copies a File to directory if toFile exists, it is brutally overwritten unless fromFile equals toFile |
static boolean |
createNewFile(File file)
similar to File.createFile but also creates any required directories |
static boolean |
deleteAll(File dirToZapp)
very brutal tree zapper that will delete a file or directory tree recursively |
static File |
ensureFileInDir(File fromFile,
File toDir)
copies a File to directory if and only if toFile does not exist |
static boolean |
equals(File file1,
File file2)
checks the equivalence of files - todo os specific behavior (just in case) |
static byte[] |
fileToByteArray(File file)
read a file into a byte array |
static boolean |
forceDelete(File file)
forces deletion of a file |
static BufferedInputStream |
getBufferedInputStream(File file)
create a buffered input stream for a file |
static BufferedOutputStream |
getBufferedOutputStream(File file)
create a buffered output stream for a file |
static BufferedOutputStream |
getBufferedOutputStream(File file,
boolean append)
create a buffered output stream for a file |
static File |
getCreateDirectory(String newDir)
create a new directory and return null if the directory could not be created |
static String |
getExtension(File file)
|
static File |
getFileInDirectory(File dir,
File localFile)
returns a File object corresponding to an instance of localFile placed in dir - No OS calls are made and File is NOT created |
static boolean |
isAbsoluteFile(File f)
check whether a file is absolute |
static boolean |
isAbsoluteFile(String f)
|
static boolean |
isDirectory(File f)
check whether a file is a directory. |
static boolean |
isDirectory(String s)
check whether a file is a directory. |
static boolean |
isWindows()
|
static File[] |
listDirectories(File dir)
list all direct child directories |
static Vector<File> |
listFilesInTree(File dir,
FileFilter filter)
list all files matching given regexp |
static Vector<File> |
listFilesInTree(File dir,
String expression)
list all files matching given regexp |
static File[] |
listFilesWithExpression(File dir,
String expression)
list all files matching given regexp |
static File[] |
listFilesWithExtension(File dir,
String extension)
list all files with a given extension (directories are skipped |
static boolean |
moveFile(File fromFile,
File toFile)
moves a File by trying to rename, if this fails, a copy with subsequent delete is performed. if toFile exists, it is brutally overwritten |
static File |
moveFileToDir(File fromFile,
File toDir)
moves a File to directory by trying to rename, if this fails, a copy with subsequent delete is performed. if toFile exists, it is brutally overwritten |
static File |
newExtension(File f,
String newExt)
create a File object with a new extension |
static File |
streamToFile(InputStream fis,
File fil)
|
static File |
streamToFile(InputStream fis,
String fileName)
dump a stream to a newly created file |
static File |
writeFile(IStreamWriter w,
File file)
write to a file |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static File[] listFilesWithExtension(File dir,
String extension)
dir - the directory to searchextension - comma separated list of extensions to check for (null = list all)
public static File[] listFilesWithExpression(File dir,
String expression)
dir - the directory to searchexpression - regular expression - uses the simplified syntax
public static Vector<File> listFilesInTree(File dir,
FileFilter filter)
dir - the directory to searchfilter - the filter to apply to files
public static Vector<File> listFilesInTree(File dir,
String expression)
dir - the directory to searchexpression - comma separated list of regular expression of a tree with slashes separating directories
public static File[] listDirectories(File dir)
dir - the directory to search
public static boolean deleteAll(File dirToZapp)
dirToZapp - the file directory to utterly anihilate
public static File streamToFile(InputStream fis,
String fileName)
fis - the inputstream to readfileName - the file to stream to
public static File writeFile(IStreamWriter w,
File file)
file - the file to writew - the writer to write to
public static File newExtension(File f,
String newExt)
f - the file, if null always returns nullnewExt - the new extension
for details of handling null etc.
public static File streamToFile(InputStream fis,
File fil)
fis - the InputStream to read - if null nothing happensfil - the file to stream to
public static byte[] fileToByteArray(File file)
file - the file to read into a byte array
public static File moveFileToDir(File fromFile,
File toDir)
fromFile - the File to movetoDir - the Directory to move to
public static boolean moveFile(File fromFile,
File toFile)
fromFile - the File to movetoFile - the File to create
public static boolean copyBytes(byte[] buf,
File toFile)
buf - the source buffertoFile - the destination File
public static boolean copyFile(File fromFile,
File toFile)
fromFile - the source FiletoFile - the destination File
public static File ensureFileInDir(File fromFile,
File toDir)
fromFile - the File to movetoDir - the Directory to move to
public static File cleanDots(File file)
file - the file to clean
public static File copyFileToDir(File fromFile,
File toDir)
fromFile - the File to movetoDir - the Directory to move to
public static File getFileInDirectory(File dir,
File localFile)
dir - the File Object representing the directorylocalFile - the local file to place in dir, note that only the path is copied - this does copy trees
public static boolean forceDelete(File file)
file - the file to delete
public static File getCreateDirectory(String newDir)
newDir - the path or URL of the new directory
public static File cleanURL(File f)
f - the file to cleanup
public static boolean isDirectory(File f)
f - the file to test
public static boolean isDirectory(String s)
s - the file to test
public static boolean isAbsoluteFile(File f)
f - the file to test
public static boolean isAbsoluteFile(String f)
f - the file path to test
public static String getExtension(File file)
file -
public static boolean createNewFile(File file)
file - the file to create
public static boolean equals(File file1,
File file2)
file1 - file2 -
public static BufferedInputStream getBufferedInputStream(File file)
file -
public static BufferedOutputStream getBufferedOutputStream(File file)
file -
public static BufferedOutputStream getBufferedOutputStream(File file,
boolean append)
file - append -
public static boolean isWindows()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||