public class FileUtil extends Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyFile(File source,
File destination)
Copies the contents of file source to file
destination.
|
static void |
createDirIfNotExists(File dir)
Creates a directory if it doesn't exist yet.
|
static File |
createTempDir(String prefix)
Creates a new and empty directory in the default temp directory using the
given prefix.
|
static boolean |
deleteChildren(File directory)
Deletes all files and directories in the specified directory.
|
static void |
deleteDir(File dir)
Deletes the specified diretory and any files and directories in it
recursively.
|
static boolean |
deleteFiles(File directory)
Deletes all files and directories in the specified directory.
|
static boolean |
deltree(File directory)
Deletes the given file and everything under it.
|
static String |
getFileExtension(String fileName)
Gets the extension of the specified file name.
|
static File |
getRelativeFile(File subj,
File relativeTo)
Gets the relative representations of a file compared to another.
|
static String |
getRelativePath(File subj,
File relativeTo)
Gets the relative representations of a file compared to another.
|
static boolean |
isLegalFileName(String fileName)
Checks whether the specified file name is a legal (DOS/Windows-) file
name.
|
static boolean |
isLegalFileNameChar(char c)
Checks whether the specified character is a legal (DOS/Windows-) file
name character.
|
static boolean |
moveRecursive(File from,
File to,
Collection<File> excludes)
Moves the given file and all files under it (if it's a directory) to the
given location, excluding the given collection of File objects!
|
public static String getRelativePath(File subj, File relativeTo)
subj
- The File to find the relative form for.relativeTo
- The File 'subj' should be made relative to.public static File getRelativeFile(File subj, File relativeTo)
subj
- The File to find the relative form for.relativeTo
- The File 'subj' should be made relative to.public static String getFileExtension(String fileName)
fileName
- A file name.public static boolean isLegalFileName(String fileName)
public static boolean isLegalFileNameChar(char c)
public static void copyFile(File source, File destination) throws IOException
IOException
public static void createDirIfNotExists(File dir) throws IOException
dir
- The directory to create.IOException
- If the creation of the directory failed.public static boolean deltree(File directory)
public static boolean deleteFiles(File directory)
public static boolean deleteChildren(File directory)
public static boolean moveRecursive(File from, File to, Collection<File> excludes)
from
- File or directory to be movedto
- The file or directory to rename toexcludes
- The File objects to be excluded; if a directory is excluded, all
files under it are excluded as well!public static File createTempDir(String prefix) throws IOException
File.createTempFile(java.lang.String, java.lang.String, java.io.File)
to create a
new tmp file, deletes it and creates a directory for it instead.prefix
- The prefix string to be used in generating the diretory's
name; must be at least three characters long.IOException
- If no directory could be created.public static void deleteDir(File dir) throws IOException
dir
- The directory to remove.IOException
- If the directory could not be removed.Copyright © 2001-2016 Aduna. All Rights Reserved.