@OpenApiAll
public final class FileUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
copy(java.io.File srcFile,
java.io.File destFile)
Copies a file to a new location.
|
static int |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copy bytes from an
InputStream to an OutputStream . |
static int |
copy(java.io.Reader input,
java.io.Writer output)
Copy chars from a
Reader to a Writer . |
static void |
createDirectory(java.io.File file)
Create a directory denoted by abstract pathname.
|
static java.io.File |
createMrTempFile(java.lang.String prefix,
java.lang.String suffix)
Create temporary file in the
getMrTempDir() directory. |
static java.io.File |
createNonOverwriteFile(java.io.File parent,
java.lang.String child)
Create a non-overwrite file from given name and extension.
|
static java.io.File |
createNonOverwriteFile(java.io.File parent,
java.lang.String prefix,
java.lang.String suffix)
Create a non-overwrite file from given name and extension.
|
static java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.lang.String parent,
boolean useUnique)
Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. |
static boolean |
delete(java.io.File file)
Deletes the file or directory denoted by this abstract pathname.
|
static java.lang.String |
getExtension(java.io.File file)
Return extension of file.
|
static java.lang.String |
getExtension(java.lang.String filename)
Return extension of file.
|
static java.lang.String |
getMrTempDir()
Get MagicReport temporary directory.
|
static java.lang.String |
getName(java.lang.String filename)
Return name of file without extension.
|
static java.lang.String |
getTempDir()
Return system temporary directory.The default temporary-file directory is specified by the system property
java.io.tmpdir . |
static java.io.File |
getTemplateFile(java.lang.String templateFileName,
java.util.List<java.lang.String> templateLocations,
java.lang.String extension,
java.lang.Object marker)
Get Template file from template file name/path.
|
static java.io.File |
getTemplateFile(java.lang.String templateFileName,
java.lang.String templateLocation)
Get Template file from template file name/path.
|
static java.io.File |
getTemplateFile(java.lang.String templateFileName,
java.lang.String templateLocation,
java.lang.String extension,
java.lang.Object marker)
Get Template file from template file name/path.
|
static java.io.File |
normalize(java.io.File file)
Convert the given file to normal form.
|
static java.lang.String |
normalize(java.lang.String name)
Convert the given name string to normal form.
|
static java.io.File[] |
recursiveFileList(java.io.File basedDir)
Recursive to get all files in
basedDir . |
static java.net.URL[] |
recursiveFileURLList(java.io.File basedDir)
Recursive to get all resources in
basedDir . |
static void |
track(java.io.File file,
java.lang.Object marker)
Track the specified file, using the provided marker, deleting the file when the marker instance is garbage
collected.
|
static void |
track(java.lang.String path,
java.lang.Object marker)
Track the specified file, using the provided marker, deleting the file when the marker instance is garbage
collected.
|
public static java.io.File createNonOverwriteFile(java.io.File parent, java.lang.String prefix, java.lang.String suffix)
Example: createNonOverwriteFile(parent, "filename", "txt");
// result of this method is "filename.txt"
// if "filename.txt" already exists, the new file name is "filename(1).txt"
parent
- The directory in which the file is to be createdprefix
- The prefix string to be used in generating the file's namesuffix
- The suffix string to be used in generating the file's name; may be extension of file.public static java.io.File createNonOverwriteFile(java.io.File parent, java.lang.String child)
Example: createNonOverwriteFile(parent, "filename", "txt");
// result of this method is "filename.txt"
// if "filename.txt" already exists, the new file name is "filename(1).txt"
parent
- The directory in which the file is to be createdchild
- The child pathname stringpublic static java.lang.String getExtension(java.io.File file)
file
- file to find an extensionpublic static java.lang.String getExtension(java.lang.String filename)
filename
- file namepublic static java.lang.String getName(java.lang.String filename)
filename
- file namepublic static java.net.URL[] recursiveFileURLList(java.io.File basedDir)
basedDir
. Return array of file URL
, or array
length zero if no file found.basedDir
- root directoryarray
of file URL
public static java.io.File[] recursiveFileList(java.io.File basedDir)
basedDir
. Return array of File
, or array length zero
if no file found.basedDir
- root directoryarray
of File
public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.lang.String parent, boolean useUnique) throws java.io.IOException
track(File,Object)
or
java.io.File#deleteOnExit()
method.
parent
argument is null
then the system-dependent default temporary-file
directory will be used. The default temporary-file directory is specified by the system property
java.io.tmpdir
.
prefix + unique_number + suffix
prefix
- The prefix string to be used in generating the file's name; must be at least three characters
longsuffix
- The suffix string to be used in generating the file's name; may be null
, in which
case the suffix ".tmp"
will be usedparent
- The directory in which the file is to be created, or null
if the default
temporary-file directory is to be useduseUnique
- if true always create unique file name.java.lang.IllegalArgumentException
- If the prefix
argument contains fewer than three charactersjava.io.IOException
- If a file could not be createdpublic static java.io.File createMrTempFile(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
getMrTempDir()
directory.
This equals to createTempFile(prefix, suffix,
getMrTempDir(), true)
.
prefix
- The prefix string to be used in generating the file's name; must be at least three characters
longsuffix
- The suffix string to be used in generating the file's name; may be null
, in which
case the suffix ".tmp"
will be usedjava.io.IOException
- If a file could not be createdpublic static java.lang.String getTempDir()
java.io.tmpdir
. On UNIX systems the default value of this property is typically "
/tmp
" or "/var/tmp
"; on Microsoft Windows systems it is typically "
C:\\WINNT\\TEMP
". A different value may be given to this system property when the Java virtual
machine is invokedpublic static java.lang.String getMrTempDir()
The MagicReport directory is
. The directory will be automatically
created if it doesn't exist.getTempDir()
+"mr/"
getTempDir()
public static int copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
InputStream
to an OutputStream
.
BufferedInputStream
.input
- the InputStream
to read fromoutput
- the OutputStream
to write tojava.lang.NullPointerException
- if the input or output is nulljava.io.IOException
- if an I/O error occurspublic static int copy(java.io.Reader input, java.io.Writer output) throws java.io.IOException
Reader
to a Writer
.
BufferedReader
.input
- the Reader
to read fromoutput
- the Writer
to write tojava.lang.NullPointerException
- if the input or output is nulljava.io.IOException
- if an I/O error occurspublic static void copy(java.io.File srcFile, java.io.File destFile) throws java.io.IOException
This method copies the contents of the specified source file or directory to the specified destination file or directory. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
srcFile
- an existing file to copy, must not be null
destFile
- the new file, must not be null
java.io.IOException
- if an error occurspublic static boolean delete(java.io.File file)
file
- the file or directory to be deletedtrue
if and only if the file or directory is successfully deleted; false
otherwisejava.lang.SecurityException
- If a security manager exists and its
SecurityManager.checkDelete(java.lang.String)
method denies delete access to the filepublic static void createDirectory(java.io.File file) throws java.io.IOException
\/?*:"<>|
file
- directory to be created.java.io.IOException
- if false to create directory.public static java.io.File normalize(java.io.File file)
file
- filepublic static java.lang.String normalize(java.lang.String name)
name
- name of filepublic static void track(java.io.File file, java.lang.Object marker)
file
- The file to be tracked.marker
- The marker object used to track the file.public static void track(java.lang.String path, java.lang.Object marker)
path
- The full path to the file to be tracked.marker
- The marker object used to track the file.public static java.io.File getTemplateFile(java.lang.String templateFileName, java.lang.String templateLocation)
templateFileName
- template file name or pathtemplateLocation
- template locationpublic static java.io.File getTemplateFile(java.lang.String templateFileName, java.lang.String templateLocation, java.lang.String extension, java.lang.Object marker)
templateFileName
- template file name or pathtemplateLocation
- template locationextension
- extension for template file. in case it has no extensionmarker
- The marker object used to track the file.public static java.io.File getTemplateFile(java.lang.String templateFileName, java.util.List<java.lang.String> templateLocations, java.lang.String extension, java.lang.Object marker)
templateFileName
- template file name or pathtemplateLocations
- list of possible locationsextension
- extension for template file. in case it has no extensionmarker
- The marker object used to track the file.Copyright © 2010 - No Magic Asia