|
APTCONVERT 1.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectfr.pixware.util.FileUtil
public class FileUtil
A collection of utility functions (static methods) operating on files and directories.
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static void |
copyFile(java.lang.String srcFileName,
java.lang.String dstFileName)
Copy a file. |
static java.lang.String |
defaultEncoding()
Returns the default character encoding for this platform. |
static void |
emptyDirectory(java.io.File dir)
Recursively deletes all the entries of a directory. |
static void |
emptyDirectory(java.lang.String dirName)
Recursively deletes all the entries of a directory. |
static java.lang.String |
fileBaseName(java.lang.String fileName)
Returns the base name part in a file path name. |
static java.lang.String |
fileDirName(java.lang.String fileName)
Returns the directory part in a file path name. |
static java.lang.String |
fileExtension(java.lang.String fileName)
Returns the file extension part in a file path name. |
static java.net.URL |
fileToURL(java.io.File file)
Converts a File to a file: URL. |
static java.net.URL |
fileToURL(java.lang.String fileName)
Converts a file name to a file: URL. |
static java.lang.String |
fileToURLName(java.lang.String fileName)
Converts a file name to a file: URL name. |
static boolean |
isGzipped(java.lang.String fileName)
Tests if a file has been compressed using gzip. |
static byte[] |
loadBytes(java.io.InputStream source)
Loads the content of an InputStream returning binary data. |
static byte[] |
loadBytes(java.lang.String fileName)
Loads the content of a binary file. |
static byte[] |
loadBytes(java.net.URL url)
Loads the content of an URL containing binary data. |
static java.lang.String |
loadGzippedString(java.io.InputStream source,
java.lang.String encoding)
Loads the content of an InputStream returning text compressed using gzip. |
static java.lang.String |
loadGzippedString(java.lang.String fileName)
Loads the content of a text file compressed using gzip. |
static java.lang.String |
loadGzippedString(java.net.URL url)
Loads the content of an URL containing text compressed using gzip. |
static java.lang.String |
loadString(java.io.InputStream stream)
Loads the content of an InputStream returning text. |
static java.lang.String |
loadString(java.lang.String fileName)
Loads the content of a text file. |
static java.lang.String |
loadString(java.net.URL url)
Loads the content of an URL containing text. |
static void |
main(java.lang.String[] args)
A simple test for all functions dealing with file path names. |
static boolean |
removeFile(java.io.File file,
boolean force)
Deletes a file or a directory, possibly emptying the directory before deleting it. |
static boolean |
removeFile(java.lang.String fileName)
Deletes a file or an empty directory. |
static boolean |
removeFile(java.lang.String fileName,
boolean force)
Deletes a file or a directory, possibly emptying the directory before deleting it. |
static void |
saveString(java.lang.String string,
java.io.OutputStream stream)
Saves some text to an OutputStream. |
static void |
saveString(java.lang.String string,
java.lang.String fileName)
Saves some text to a file. |
static java.lang.String |
trimFileExtension(java.lang.String fileName)
Returns a file path name without its file extension part. |
static java.io.File |
urlToFile(java.lang.String urlName)
Converts a file: URL name to a File. |
static java.io.File |
urlToFile(java.net.URL url)
Converts a file: URL to a File. |
static java.lang.String |
urlToFileName(java.lang.String urlName)
Converts a file: URL name to a file name. |
| 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 java.io.File urlToFile(java.net.URL url)
url - the URL to be converted
null if
url is not a file: URLpublic static java.io.File urlToFile(java.lang.String urlName)
urlName - the URL name to be converted
null if
urlName is not a file: URLpublic static java.lang.String urlToFileName(java.lang.String urlName)
urlName - the URL name to be converted
null if
urlName is not a file: URLpublic static java.net.URL fileToURL(java.io.File file)
file - the file to be converted
public static java.net.URL fileToURL(java.lang.String fileName)
fileName - the file name to be converted
public static java.lang.String fileToURLName(java.lang.String fileName)
fileName - the file name to be converted
public static java.lang.String fileDirName(java.lang.String fileName)
On Windows, '/' is used as an alternate file path name separator.
Examples:
| Path | Result |
|---|---|
| util/FileUtil.java | util |
| FileUtil.java | . (dot) |
fileName - a file path name
public static java.lang.String fileBaseName(java.lang.String fileName)
On Windows, '/' is used as an alternate file path name separator.
| Path | Result |
|---|---|
| util/FileUtil.java | FileUtil.java |
| FileUtil.java | FileUtil.java |
fileName - a file path name
public static java.lang.String fileExtension(java.lang.String fileName)
On Windows, '/' is used as an alternate file path name separator.
| Path | Result |
|---|---|
| util/FileUtil.java | .java |
| makefile | "" (empty string) |
| /home/hussein/.profile | "" (empty string) |
fileName - a file path name
If the base name without its extension is empty, the path is considered not to have an extension part. This is the case of /home/hussein/.profile in the examples above.
public static java.lang.String trimFileExtension(java.lang.String fileName)
On Windows, '/' is used as an alternate file path name separator.
| Path | Result |
|---|---|
| util/FileUtil.java | util/FileUtil |
| makefile | makefile |
| /home/hussein/.profile | /home/hussein/.profile |
fileName - a file path name
public static void main(java.lang.String[] args)
public static boolean removeFile(java.lang.String fileName)
fileName - the name of the file or empty directory to be deleted
true if the file or directory has been
successfully deleted; false otherwise
public static boolean removeFile(java.lang.String fileName,
boolean force)
fileName - the name of the file or directory to be deletedforce - if true and the file to be deleted is a
non-empty directory, empty it before attempting to delete it; if
false, do not empty directories
true if the file or directory has been
successfully deleted; false otherwise
public static boolean removeFile(java.io.File file,
boolean force)
file - the file or directory to be deletedforce - if true and the file to be deleted is a
non-empty directory, empty it before attempting to delete it; if
false, do not empty directories
true if the file or directory has been
successfully deleted; false otherwisepublic static void emptyDirectory(java.lang.String dirName)
dirName - the name of the directory to be emptiedpublic static void emptyDirectory(java.io.File dir)
dir - the directory to be emptied
public static void copyFile(java.lang.String srcFileName,
java.lang.String dstFileName)
throws java.io.IOException
srcFileName - the name of the copied filedstFileName - the name of the copy
java.io.IOException - if there is an IO problem
public static java.lang.String loadString(java.lang.String fileName)
throws java.io.FileNotFoundException,
java.io.IOException
fileName - the name of the text file
java.io.IOException - if there is an IO problem
java.io.FileNotFoundException
public static java.lang.String loadString(java.net.URL url)
throws java.io.IOException
url - the URL of the text resource
java.io.IOException - if there is an IO problem
public static java.lang.String loadString(java.io.InputStream stream)
throws java.io.IOException
stream - the text source
java.io.IOException - if there is an IO problem
public static void saveString(java.lang.String string,
java.lang.String fileName)
throws java.io.IOException
string - the text to be savedfileName - the name of the file
java.io.IOException - if there is an IO problem
public static void saveString(java.lang.String string,
java.io.OutputStream stream)
throws java.io.IOException
string - the text to be savedstream - the text sink
java.io.IOException - if there is an IO problem
public static byte[] loadBytes(java.lang.String fileName)
throws java.io.IOException
fileName - the name of the binary file
java.io.IOException - if there is an IO problem
public static byte[] loadBytes(java.net.URL url)
throws java.io.IOException
url - the URL of the binary data
java.io.IOException - if there is an IO problem
public static byte[] loadBytes(java.io.InputStream source)
throws java.io.IOException
source - the binary data source
java.io.IOException - if there is an IO problem
public static boolean isGzipped(java.lang.String fileName)
throws java.io.IOException
fileName - the name of the file to be tested
true if the file has been gzip-ed,
false otherwise
java.io.IOException - if there is an IO problem
public static java.lang.String loadGzippedString(java.lang.String fileName)
throws java.io.IOException
fileName - the name of the gzip-ed file; the encoding of the text
before compression is assumed to be the default encoding of the
platform
java.io.IOException - if there is an IO problemdefaultEncoding()
public static java.lang.String loadGzippedString(java.net.URL url)
throws java.io.IOException
url - the URL of the gzip-ed data; the encoding of the text before
compression is assumed to be the default encoding of the platform
java.io.IOException - if there is an IO problemdefaultEncoding()
public static java.lang.String loadGzippedString(java.io.InputStream source,
java.lang.String encoding)
throws java.io.IOException
source - the gzip-ed data sourceencoding - the encoding of the text before compression
java.io.IOException - if there is an IO problempublic static java.lang.String defaultEncoding()
|
APTCONVERT 1.1 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||