public class FileUtils extends java.lang.Object implements FileUtilsConst
PATH_SEPARATOR, PERLINE_DEFAULT, STREAM_TRANSFER_BUFFER_SIZE
HOURS_PER_DAY, MINUTES_PER_DAY, MINUTES_PER_HOUR, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, SECONDS_PER_DAY, SECONDS_PER_MINUTE
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addStrToFileName(java.lang.String fileNameStr,
java.lang.String s)
Add a string to the end of a file name (before the extension if present.)
|
static java.io.BufferedReader |
appResourceOpen(java.lang.String nameStr)
Attempts to open the given name via either the application method.
|
static java.io.InputStream |
appResourceOpenInputStream(java.lang.String nameStr)
Attempts to open the given name via either the application method.
|
static java.io.BufferedInputStream |
appResourceOpenStream(java.lang.String nameStr)
Attempts to open the given name via application method.
|
static java.lang.String |
buildPathName(java.lang.String dirStr,
java.lang.String fileStr)
Combines the given directory and file names.
|
static java.lang.String |
buildPathName(java.lang.String dirStr,
java.lang.String fileStr,
boolean forwardSlashFlag)
Combines the given directory and file names.
|
static java.net.URL |
checkConnection(java.lang.String linkStr)
Check the connection.
|
static java.net.URL |
checkConnection(java.net.URL urlObj)
Check the connection.
|
static void |
close(java.io.Closeable closeable)
Close the Closeable object.
|
static boolean |
closeStream(java.io.InputStream inputStreamObj)
Closes the given input stream.
|
static boolean |
closeStream(java.io.OutputStream outputStreamObj)
Closes the given output stream.
|
static void |
copyFile(java.io.File sourceFileObj,
java.io.File destFileObj)
Copies one file to another.
|
static void |
copyFile(java.io.File sourceFileObj,
java.io.File destFileObj,
boolean copyLastModFlag)
Copies one file to another.
|
static void |
copyFile(java.lang.String sourceFileNameStr,
java.lang.String destFileNameStr)
Copies one file to another.
|
static void |
copyFile(java.lang.String sourceFileNameStr,
java.lang.String destFileNameStr,
boolean copyLastModFlag)
Copies one file to another.
|
static void |
copyLastModifiedTime(java.io.File sourceFileObj,
java.io.File destFileObj)
Copies the last-modified-time value from one file to another.
|
static java.lang.String |
createBackupFileName(java.lang.String fileNameStr)
Creates a backup file name for the specified file name.
|
static java.lang.String |
createBackupFileName(java.lang.String fileNameStr,
java.lang.String backupStr)
Creates a backup file name for the specified file name.
|
static boolean |
createParentDirs(java.io.File fileObj)
Creates any needed parent directories needed for the given file
object.
|
static boolean |
createParentDirs(java.lang.String nameStr)
Creates any needed parent directories needed for the given file/path
name.
|
static java.io.File |
createUnusedFileNameObj(java.lang.String tmplStr,
java.io.File parentDirFileObj,
boolean useTimeFlag)
Creates a new 'File' object that references an unused file name.
|
static java.io.File |
createUnusedFileNameObj(java.lang.String tmplStr,
java.io.File parentDirFileObj,
boolean useTimeFlag,
boolean fileExtFlag)
Creates a new 'File' object that references an unused file name.
|
static java.io.File |
createUnusedFileNameObj(java.lang.String tmplStr,
java.lang.String parentDirStr,
boolean useTimeFlag)
Creates a new 'File' object that references an unused file name.
|
static java.io.File |
createUnusedFileNameObj(java.lang.String tmplStr,
java.lang.String parentDirStr,
boolean useTimeFlag,
boolean fileExtFlag)
Creates a new 'File' object that references an unused file name.
|
static boolean |
deleteDirectory(java.io.File dir)
Deletes the directory and any subdirectories.
|
static void |
deleteFiles(java.io.File file)
Deletes the specified file or if a directory is specified deletes the
directory and any subdirectories.
|
static void |
deleteFiles(java.io.File[] fileList,
int maxAgeDays)
Deletes files in the specified list that are older than the given age.
|
static void |
deleteFiles(java.io.File[] fileList,
long maxAgeMs)
Deletes files in the specified list that are older than the given age.
|
static void |
deleteOldFiles(java.io.File directoryObj,
int maxAgeDays)
Deletes files older than the given age from the specified directory.
|
static void |
deleteOldFiles(java.io.File directoryObj,
int maxAgeDays,
java.lang.String filterStr)
Deletes files older than the given age from the specified directory.
|
static void |
deleteOldFiles(java.io.File directoryObj,
long maxAgeMs)
Deletes files older than the given age from the specified directory.
|
static void |
deleteOldFiles(java.io.File directoryObj,
long maxAgeMs,
java.lang.String filterStr)
Deletes files older than the given age from the specified directory.
|
static void |
deleteOldFiles(java.nio.file.Path directory,
long maxAgeMs,
java.lang.String filterStr)
Deletes files older than the given age from the specified directory.
|
protected static java.io.InputStream |
doFileMultiOpenInputStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
protected static java.io.InputStream |
doFileMultiOpenInputStream(java.lang.String nameStr,
java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
protected static java.net.URL |
doFileMultiOpenInputURL(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
protected static java.net.URL |
doGetURL(java.lang.String nameStr)
Attempts to get a URL from the given name as a URL,
as a local file, and as a system resource (whichever works first).
|
static boolean |
endsWithDirSepChar(java.lang.String str)
Returns an indicator of whether or not the given string ends with
a directory separator character.
|
static boolean |
existsMultiOpen(java.lang.String nameStr)
Determines if the given name denotes an existing local file or a
URL or 'jar'-file resource that may be accessed.
|
static java.io.BufferedReader |
fileMultiOpen(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.io.BufferedReader |
fileMultiOpen(java.lang.String nameStr,
java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.io.InputStream |
fileMultiOpenInputStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.io.InputStream |
fileMultiOpenInputStream(java.lang.String nameStr,
java.util.Properties urlRequestProps)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.net.URL |
fileMultiOpenInputURL(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.io.BufferedInputStream |
fileMultiOpenStream(java.lang.String nameStr)
Attempts to open the given name as a local file, as a URL, as a
resource and as an entry in a 'jar' file (whichever works first).
|
static java.io.BufferedReader |
getBufferedReader(java.io.InputStream stmObj)
Gets a buffered reader for the specified input stream.
|
static java.io.BufferedReader |
getBufferedReader(java.io.InputStream stmObj,
java.lang.String charsetName)
Gets a buffered reader for the specified input stream.
|
static long |
getFileAge(java.io.File f,
long currentTime) |
static java.lang.String |
getFileExtension(java.lang.String fileNameStr)
Returns the extension portion of the file name string
or null if none (does not include the ".".)
|
static int |
getFileExtensionIndex(java.lang.String fileNameStr)
Returns the index of the extension portion of the file name string.
|
static long |
getFileLength(java.lang.String nameStr)
Returns the file-length value for the file denoted by the
given name.
|
static java.lang.String |
getFileNameWithoutExtension(java.lang.String fileNameStr)
Returns the file name string without the extension portion.
|
static long |
getLastModifiedTime(java.lang.String nameStr)
Returns the last-modified time value for the file denoted by the
given name.
|
static java.io.File |
getUniqueFile(java.io.File fileObj,
java.lang.String prefix)
Get a unique file for the specified file.
|
static java.net.URL |
getURL(java.lang.String nameStr)
Attempts to get a URL from the given name as a URL,
as a local file, and as a system resource (whichever works first).
|
static java.lang.String |
getWorkingDirPath()
Get the working directory path.
|
static void |
hexdump(java.io.InputStream is,
java.lang.Appendable out,
int perline)
Dump the file.
|
static boolean |
isDirSepChar(char ch)
Returns an indicator of whether or not the given character is
a directory separator character.
|
static java.io.File[] |
listAllFiles(java.io.File dirFileObj,
java.io.FileFilter filterObj)
Returns an array of abstract pathnames denoting the requested files in
the specified directory and all subdirectories.
|
static java.io.File[] |
listFiles(java.io.File directoryObj)
Returns an array of abstract pathnames denoting the files in the
specified directory.
|
static java.io.File[] |
listFiles(java.io.File directoryObj,
java.io.FileFilter filter)
Returns an array of abstract pathnames denoting the files in the
specified directory.
|
static void |
main(java.lang.String[] args)
Test program to process one or more files.
|
static void |
moveFile(java.io.File sourceFileObj,
java.io.File destDirFileObj)
Moves the specified file to a new location (even if the new location
is on a different filesystem).
|
static void |
moveFile(java.lang.String sourceFileNameStr,
java.lang.String destDirNameStr)
Moves the specified file to a new location (even if the new location
is on a different filesystem).
|
static java.net.URLConnection |
openConnection(java.net.URL urlObj)
Open the URL connection.
|
static java.net.URLConnection |
openConnection(java.net.URL urlObj,
boolean checkResponse)
Open the URL connection.
|
static void |
printUsage()
Print the usage.
|
static void |
readFileTail(java.lang.String sourceFileNameStr,
long numberOfLines,
java.io.OutputStream outputStreamObj)
Reads given number of lines from tail end of given file.
|
static byte[] |
readFileToBuffer(java.io.File fileObj)
Reads data from a file into a buffer.
|
static byte[] |
readFileToBuffer(java.lang.String fileNameStr)
Reads data from a file into a buffer.
|
static java.lang.String |
readFileToString(java.io.File fileObj)
Reads data from a file into a string.
|
static java.lang.String |
readFileToString(java.io.File fileObj,
java.lang.String charsetNameStr)
Reads data from a file into a string.
|
static java.lang.String |
readFileToString(java.lang.String fileNameStr)
Reads data from a file into a string.
|
static java.lang.String |
readFileToString(java.lang.String fileNameStr,
java.lang.String charsetNameStr)
Reads data from a file into a string.
|
static byte[] |
readMultiOpenFileToBuffer(java.lang.String fileNameStr)
Reads data from a file into a byte array, where the given name may
specify a local file, a URL, a resource or an entry in a 'jar' file
(whichever works first).
|
static java.lang.String |
readMultiOpenFileToString(java.lang.String fileNameStr)
Reads data from a file into a string, where the given name may specify
a local file, a URL, a resource or an entry in a 'jar' file (whichever
works first).
|
static byte[] |
readStreamToBuffer(java.io.InputStream stmObj)
Reads data from an input stream into a byte array.
|
static java.lang.String |
readStreamToString(java.io.BufferedReader rdrObj)
Reads data from an input stream into a string.
|
static java.lang.String |
readStreamToString(java.io.InputStream stmObj)
Reads data from an input stream into a string.
|
static java.lang.String |
readStreamToString(java.io.InputStream inStmObj,
java.lang.String charsetNameStr)
Reads data from an input stream into a string.
|
static java.lang.String |
removeLeadingDotDir(java.lang.String fileNameStr)
Removes leading "dot" directory from given filename.
|
static void |
transferStream(java.io.InputStream inputStreamObj,
java.io.OutputStream outputStreamObj)
Transfers data from the input stream to the output stream.
|
static void |
transferStream(java.io.InputStream inputStreamObj,
java.io.OutputStream outputStreamObj,
CallBackCompletion callBack)
Transfers data from the input stream to the output stream.
|
static void |
transferStream(java.io.InputStream inputStreamObj,
java.io.OutputStream outputStreamObj,
long maxBytesLimit)
Transfers data from the input stream to the output stream.
|
static boolean |
urlExists(java.net.URL urlObj)
Tests whether the specified URL exists.
|
static void |
writeBufferToFile(java.lang.String fileNameStr,
byte[] btArr)
Writes a data buffer to a file.
|
static void |
writeStringToFile(java.io.File fileObj,
java.lang.String dataStr)
Writes a data string to a file.
|
static void |
writeStringToFile(java.io.File fileObj,
java.lang.String dataStr,
boolean appendFlag)
Writes a data string to a file.
|
static void |
writeStringToFile(java.io.File fileObj,
java.lang.String dataStr,
boolean appendFlag,
java.lang.String charsetNameStr)
Writes a data string to a file.
|
static void |
writeStringToFile(java.io.File fileObj,
java.lang.String dataStr,
java.lang.String charsetNameStr)
Writes a data string to a file.
|
static void |
writeStringToFile(java.lang.String fileNameStr,
java.lang.String dataStr)
Writes a data string to a file.
|
static void |
writeStringToFile(java.lang.String fileNameStr,
java.lang.String dataStr,
boolean appendFlag)
Writes a data string to a file.
|
static void |
writeStringToFile(java.lang.String fileNameStr,
java.lang.String dataStr,
boolean appendFlag,
java.lang.String charsetNameStr)
Writes a data string to a file.
|
static void |
writeStringToFile(java.lang.String fileNameStr,
java.lang.String dataStr,
java.lang.String charsetNameStr)
Writes a data string to a file.
|
public static void printUsage()
public static void main(java.lang.String[] args)
args
- the file names.public static void hexdump(java.io.InputStream is, java.lang.Appendable out, int perline) throws java.io.IOException
is
- the input stream.out
- the output.perline
- the number of values per line.java.io.IOException
- if an I/O error occurs.FileUtilsConst.PERLINE_DEFAULT
public static java.lang.String addStrToFileName(java.lang.String fileNameStr, java.lang.String s)
fileNameStr
- the name of the file.s
- string to add.public static java.io.BufferedReader appResourceOpen(java.lang.String nameStr)
nameStr
- file name string.public static java.io.InputStream appResourceOpenInputStream(java.lang.String nameStr)
nameStr
- file name string.public static java.io.BufferedInputStream appResourceOpenStream(java.lang.String nameStr)
nameStr
- file name string.public static java.lang.String buildPathName(java.lang.String dirStr, java.lang.String fileStr)
dirStr
- the directory name to use.fileStr
- the file name to use.public static java.lang.String buildPathName(java.lang.String dirStr, java.lang.String fileStr, boolean forwardSlashFlag)
dirStr
- the directory name to use.fileStr
- the file name to use.forwardSlashFlag
- true to replace all backslash characters ('\')
in the path with forward-slash characters ('/').public static java.net.URL checkConnection(java.lang.String linkStr)
linkStr
- the link string.public static java.net.URL checkConnection(java.net.URL urlObj)
urlObj
- the URL.public static void close(java.io.Closeable closeable)
closeable
- the Closeable object or null if none.public static boolean closeStream(java.io.InputStream inputStreamObj)
inputStreamObj
- the input stream.public static boolean closeStream(java.io.OutputStream outputStreamObj)
outputStreamObj
- the output stream.public static void copyFile(java.io.File sourceFileObj, java.io.File destFileObj) throws java.io.FileNotFoundException, java.io.IOException
sourceFileObj
- source file object.destFileObj
- destination file object.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static void copyFile(java.io.File sourceFileObj, java.io.File destFileObj, boolean copyLastModFlag) throws java.io.FileNotFoundException, java.io.IOException
sourceFileObj
- source file object.destFileObj
- destination file object.copyLastModFlag
- true to set the last-modified-time value
for the destination file to that of the source file.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static void copyFile(java.lang.String sourceFileNameStr, java.lang.String destFileNameStr) throws java.io.FileNotFoundException, java.io.IOException
sourceFileNameStr
- name of source file.destFileNameStr
- name of destination file.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static void copyFile(java.lang.String sourceFileNameStr, java.lang.String destFileNameStr, boolean copyLastModFlag) throws java.io.FileNotFoundException, java.io.IOException
sourceFileNameStr
- name of source file.destFileNameStr
- name of destination file.copyLastModFlag
- true to set the last-modified-time value
for the destination file to that of the source file.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static void copyLastModifiedTime(java.io.File sourceFileObj, java.io.File destFileObj)
sourceFileObj
- source file object.destFileObj
- destination file object.java.lang.SecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String)
method denies write access to the named file.public static java.lang.String createBackupFileName(java.lang.String fileNameStr)
fileNameStr
- the name of the file.public static java.lang.String createBackupFileName(java.lang.String fileNameStr, java.lang.String backupStr)
fileNameStr
- the name of the file.backupStr
- backup string to be added (bak) or null for none.public static boolean createParentDirs(java.io.File fileObj)
fileObj
- the file object to use.public static boolean createParentDirs(java.lang.String nameStr)
nameStr
- file name string.public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.io.File parentDirFileObj, boolean useTimeFlag)
tmplStr
- the template to use when generating the file name,
or null for none.parentDirFileObj
- the File object for the parent directory to
use, or null to use the current user directory.useTimeFlag
- if true then the current time value (in ms since
1/1/1970) is used in the file name, if false then an incrementing
value is used, starting at 1 (if the template string name itself
is already in use).public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.io.File parentDirFileObj, boolean useTimeFlag, boolean fileExtFlag)
tmplStr
- the template to use when generating the file name,
or null for none.parentDirFileObj
- the File object for the parent directory to
use, or null to use the current user directory.useTimeFlag
- if true then the current time value (in ms since
1/1/1970) is used in the file name, if false then an incrementing
value is used, starting at 1 (if the template string name itself
is already in use).fileExtFlag
- true to insert numeric value before the filename
extension (if present); false to always append numeric value to end.public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.lang.String parentDirStr, boolean useTimeFlag)
tmplStr
- the template to use when generating the file name,
or null for none.parentDirStr
- the name of the parent directory to use, or
null to use the current user directory.useTimeFlag
- if true then the current time value (in ms since
1/1/1970) is used in the file name, if false then an incrementing
value is used, starting at 1 (if the template string name itself
is already in use).public static java.io.File createUnusedFileNameObj(java.lang.String tmplStr, java.lang.String parentDirStr, boolean useTimeFlag, boolean fileExtFlag)
tmplStr
- the template to use when generating the file name,
or null for none.parentDirStr
- the name of the parent directory to use, or
null to use the current user directory.useTimeFlag
- if true then the current time value (in ms since
1/1/1970) is used in the file name, if false then an incrementing
value is used, starting at 1 (if the template string name itself
is already in use).fileExtFlag
- true to insert numeric value before the filename
extension (if present); false to always append numeric value to end.public static boolean deleteDirectory(java.io.File dir)
dir
- the directory to delete.public static void deleteFiles(java.io.File file)
file
- the 'File' object to delete.public static void deleteFiles(java.io.File[] fileList, int maxAgeDays)
fileList
- the array of 'File' objects to delete.maxAgeDays
- the maximum number of days to keep files.listFiles
public static void deleteFiles(java.io.File[] fileList, long maxAgeMs)
fileList
- the array of 'File' objects to delete.maxAgeMs
- the maximum number of milliseconds to keep files.listFiles
public static void deleteOldFiles(java.io.File directoryObj, int maxAgeDays)
directoryObj
- the directory to use.maxAgeDays
- the maximum number of days to keep files, or 0
to delete no files.public static void deleteOldFiles(java.io.File directoryObj, int maxAgeDays, java.lang.String filterStr)
directoryObj
- the directory to use.maxAgeDays
- the maximum number of days to keep files, or 0
to delete no files.filterStr
- the file filter string to use (i.e.: "*.txt",
"temp.*", "temp.txt", "*bak*"), or null for none.IstiFileFilter.createFileFilter(java.lang.String)
public static void deleteOldFiles(java.io.File directoryObj, long maxAgeMs)
directoryObj
- the directory to use.maxAgeMs
- the maximum number of milliseconds to keep files, or
0 to delete no files.public static void deleteOldFiles(java.io.File directoryObj, long maxAgeMs, java.lang.String filterStr)
directoryObj
- the directory to use.maxAgeMs
- the maximum number of milliseconds to keep files, or 0
to delete no files.filterStr
- the file filter string to use (i.e.: "*.txt", "temp.*",
"temp.txt", "*bak*"), or null for none.IstiFileFilter.createFileFilter(java.lang.String)
public static void deleteOldFiles(java.nio.file.Path directory, long maxAgeMs, java.lang.String filterStr)
directory
- the directory to use.maxAgeMs
- the maximum number of milliseconds to keep files, or 0
to delete no files.filterStr
- the file filter string to use (i.e.: "*.txt", "temp.*",
"temp.txt", "*bak*"), or null for none.IstiFileFilter.createFileFilter(java.lang.String)
protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr)
nameStr
- file name string.protected static java.io.InputStream doFileMultiOpenInputStream(java.lang.String nameStr, java.util.Properties urlRequestProps)
nameStr
- file name string.urlRequestProps
- the request properties to use for URL connections
or null if none.protected static java.net.URL doFileMultiOpenInputURL(java.lang.String nameStr)
nameStr
- file name string.protected static java.net.URL doGetURL(java.lang.String nameStr)
nameStr
- file name string.public static boolean endsWithDirSepChar(java.lang.String str)
str
- the string to test.public static boolean existsMultiOpen(java.lang.String nameStr)
nameStr
- file name string.public static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr)
nameStr
- file name string.public static java.io.BufferedReader fileMultiOpen(java.lang.String nameStr, java.util.Properties urlRequestProps)
nameStr
- file name string.urlRequestProps
- the request properties to use for URL connections
or null if none.public static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr)
nameStr
- file name string.public static java.io.InputStream fileMultiOpenInputStream(java.lang.String nameStr, java.util.Properties urlRequestProps)
nameStr
- file name string.urlRequestProps
- the request properties to use for URL connections
or null if none.public static java.net.URL fileMultiOpenInputURL(java.lang.String nameStr)
nameStr
- file name string.public static java.io.BufferedInputStream fileMultiOpenStream(java.lang.String nameStr)
nameStr
- file name string.public static java.io.BufferedReader getBufferedReader(java.io.InputStream stmObj)
stmObj
- the input stream or null if none.public static java.io.BufferedReader getBufferedReader(java.io.InputStream stmObj, java.lang.String charsetName)
stmObj
- the input stream or null if none.charsetName
- the name of a supported charset or null for default.public static long getFileAge(java.io.File f, long currentTime)
f
- filecurrentTime
- current timepublic static java.lang.String getFileExtension(java.lang.String fileNameStr)
fileNameStr
- the name of the file.public static int getFileExtensionIndex(java.lang.String fileNameStr)
fileNameStr
- the name of the file.FileFilter.accept(java.io.File)
public static long getFileLength(java.lang.String nameStr)
nameStr
- file name string.public static java.lang.String getFileNameWithoutExtension(java.lang.String fileNameStr)
fileNameStr
- the name of the file.public static long getLastModifiedTime(java.lang.String nameStr)
nameStr
- file name string.public static java.io.File getUniqueFile(java.io.File fileObj, java.lang.String prefix)
fileObj
- the file.prefix
- the prefix text or null if none.public static java.net.URL getURL(java.lang.String nameStr)
nameStr
- file name string.public static java.lang.String getWorkingDirPath()
public static boolean isDirSepChar(char ch)
ch
- the character to test.public static java.io.File[] listAllFiles(java.io.File dirFileObj, java.io.FileFilter filterObj)
dirFileObj
- directory object to use.filterObj
- filename filter to use, or null for none.public static java.io.File[] listFiles(java.io.File directoryObj)
directoryObj
- directory object.
If the file does is not a directory, then this
method returns null
. Otherwise an array of
File
objects is returned, one for each file or directory in
the directory. Pathnames denoting the directory itself and the
directory's parent directory are not included in the result. Each
resulting abstract pathname is constructed from this abstract pathname
using the
constructor. Therefore if this pathname
is absolute then each resulting pathname is absolute; if this pathname
is relative then each resulting pathname will be relative to the same
directory.
File(File, String)
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
null
if this abstract pathname
does not denote a directory, or if an I/O error occurs.public static java.io.File[] listFiles(java.io.File directoryObj, java.io.FileFilter filter)
directoryObj
- directory objectfilter
- The filename filter to use, or null for none.null
if this abstract pathname
does not denote a directory, or if an I/O error occurs. If the file does is not a directory, then this
method returns null
. Otherwise an array of
File
objects is returned, one for each file or directory in
the directory. Pathnames denoting the directory itself and the
directory's parent directory are not included in the result. Each
resulting abstract pathname is constructed from this abstract pathname
using the {@link #File(java.io.File, java.lang.String)
File(File, String)}
constructor. Therefore if this pathname
is absolute then each resulting pathname is absolute; if this pathname
is relative then each resulting pathname will be relative to the same
directory.
There is no guarantee that the name strings in the resulting array
will appear in any specific order; they are not, in particular,
guaranteed to appear in alphabetical order.
public static void moveFile(java.io.File sourceFileObj, java.io.File destDirFileObj) throws java.io.FileNotFoundException, java.io.IOException
sourceFileObj
- source file object.destDirFileObj
- destination directory or file object.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static void moveFile(java.lang.String sourceFileNameStr, java.lang.String destDirNameStr) throws java.io.FileNotFoundException, java.io.IOException
sourceFileNameStr
- name of source file.destDirNameStr
- name of destination directory or file.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static java.net.URLConnection openConnection(java.net.URL urlObj) throws java.io.IOException
urlObj
- the URL object.java.io.IOException
- if an I/O error occurs.public static java.net.URLConnection openConnection(java.net.URL urlObj, boolean checkResponse) throws java.io.IOException
urlObj
- the URL object.checkResponse
- true to check the response code, otherwise file.java.io.IOException
- if an I/O error occurs.public static void readFileTail(java.lang.String sourceFileNameStr, long numberOfLines, java.io.OutputStream outputStreamObj) throws java.io.FileNotFoundException, java.io.IOException
sourceFileNameStr
- name of source file.numberOfLines
- number of lines to read.outputStreamObj
- output stream to send read data into.java.io.FileNotFoundException
- if the source file is not found.java.io.IOException
- if an I/O error occurs.public static byte[] readFileToBuffer(java.io.File fileObj) throws java.io.FileNotFoundException, java.io.IOException
fileObj
- the 'File' object for the input file.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static byte[] readFileToBuffer(java.lang.String fileNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileNameStr
- the name of the input file.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static java.lang.String readFileToString(java.io.File fileObj) throws java.io.FileNotFoundException, java.io.IOException
fileObj
- the input file object.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static java.lang.String readFileToString(java.io.File fileObj, java.lang.String charsetNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileObj
- the input file object.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static java.lang.String readFileToString(java.lang.String fileNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileNameStr
- the name of the input file.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static java.lang.String readFileToString(java.lang.String fileNameStr, java.lang.String charsetNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileNameStr
- the name of the input file.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static byte[] readMultiOpenFileToBuffer(java.lang.String fileNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileNameStr
- the name of the input file.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static java.lang.String readMultiOpenFileToString(java.lang.String fileNameStr) throws java.io.FileNotFoundException, java.io.IOException
fileNameStr
- the name of the input file.java.io.FileNotFoundException
- if the specified file is not found.java.io.IOException
- if an error occurred while opening or reading from
the input file.public static byte[] readStreamToBuffer(java.io.InputStream stmObj) throws java.io.IOException
stmObj
- the input stream to use.java.io.IOException
- if an error occurred while reading from the
input stream.public static java.lang.String readStreamToString(java.io.BufferedReader rdrObj) throws java.io.IOException
rdrObj
- the input stream to use.java.io.IOException
- if an error occurred while reading from the
input stream.public static java.lang.String readStreamToString(java.io.InputStream stmObj) throws java.io.IOException
stmObj
- the input stream to use.java.io.IOException
- if an error occurred while reading from the
input stream.public static java.lang.String readStreamToString(java.io.InputStream inStmObj, java.lang.String charsetNameStr) throws java.io.IOException
inStmObj
- input stream to use.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.IOException
- if an error occurred while reading from the
input stream.public static java.lang.String removeLeadingDotDir(java.lang.String fileNameStr)
fileNameStr
- filename to process.public static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj) throws java.io.IOException
inputStreamObj
- the input stream.outputStreamObj
- the output stream.java.io.IOException
- if an I/O error occurs.public static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj, CallBackCompletion callBack) throws java.io.IOException
inputStreamObj
- the input stream.outputStreamObj
- the output stream.callBack
- callBack method or null to execute on the current thread.java.io.IOException
- if an I/O error occurs.public static void transferStream(java.io.InputStream inputStreamObj, java.io.OutputStream outputStreamObj, long maxBytesLimit) throws java.io.IOException
inputStreamObj
- the input stream.outputStreamObj
- the output stream.maxBytesLimit
- the maximum number of bytes to be transferred,
or 0 for no limit.java.io.IOException
- if an I/O error occurs.public static boolean urlExists(java.net.URL urlObj) throws java.io.IOException
urlObj
- the URL.java.io.IOException
- if an I/O exception occurs.public static void writeBufferToFile(java.lang.String fileNameStr, byte[] btArr) throws java.io.IOException
fileNameStr
- the name of the output file.btArr
- the data to be written.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr) throws java.io.IOException
fileObj
- the output file object to use.dataStr
- the data to be written.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, boolean appendFlag) throws java.io.IOException
fileObj
- the output file object to use.dataStr
- the data to be written.appendFlag
- true to append to current contents of file, false
to overwrite.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, boolean appendFlag, java.lang.String charsetNameStr) throws java.io.IOException
fileObj
- the output file object to use.dataStr
- the data to be written.appendFlag
- true to append to current contents of file, false
to overwrite.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.io.File fileObj, java.lang.String dataStr, java.lang.String charsetNameStr) throws java.io.IOException
fileObj
- the output file object to use.dataStr
- the data to be written.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr) throws java.io.IOException
fileNameStr
- the name of the output file.dataStr
- the data to be written.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, boolean appendFlag) throws java.io.IOException
fileNameStr
- the name of the output file.dataStr
- the data to be written.appendFlag
- true to append to current contents of file, false
to overwrite.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, boolean appendFlag, java.lang.String charsetNameStr) throws java.io.IOException
fileNameStr
- the name of the output file.dataStr
- the data to be written.appendFlag
- true to append to current contents of file, false
to overwrite.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.IOException
- if an error occurred while opening or writing to
the output file.public static void writeStringToFile(java.lang.String fileNameStr, java.lang.String dataStr, java.lang.String charsetNameStr) throws java.io.IOException
fileNameStr
- the name of the output file.dataStr
- the data to be written.charsetNameStr
- name of charset to use for conversion from data
bytes to characters, or null for default charset.java.io.IOException
- if an error occurred while opening or writing to
the output file.