All Packages Class Hierarchy This Package Previous Next Index
Class ccl.util.FileUtil
java.lang.Object
|
+----ccl.util.FileUtil
- public class FileUtil
- extends Object
Utility class for file operations.
- Version:
- $Id: FileUtil.java,v 1.40 2000/04/16 20:38:20 clemens Exp clemens $
- Author:
-
Chr. Clemens Lee
<
clemens@kclee.com
>
-
S_SWING_JAR
-
-
S_SWINGALL_JAR
-
-
FileUtil()
-
-
_getFilteredDirContent(String, FilenameFilter)
-
Deprecated.
-
appendFile(String, String)
-
-
areAllPathsAbsolute(String)
- Tests if the file represented by this File object is an absolute pathname.
-
concatPath(String, String)
- Concatenates a file path with the file name.
-
copy(BufferedInputStream, BufferedOutputStream)
-
-
copy(InputStream, OutputStream)
-
-
copy(String, String)
-
-
copyDir(String, String)
- Like: cp -r sDir_ sDestination_
No consideration for links are in place, so be aware
of possible infinite loops.
-
delete(String)
-
-
equalsFile(String, String)
-
-
equalsPath(String, String)
-
-
exists(String)
-
-
existsDir(String)
- Tests, if a given directory exists.
-
existsFile(String)
-
-
getAbsoluteFileName(String)
-
-
getAbsolutePathList(String)
- For example: .;C:\jdk1.1.7\lib\classes.zip
-> C:\java\projects;C:\jdk1.1.7\lib\classes.zip
-
getClassPath(Object)
- Does work only when class exists outside a zip or jar file.
-
getClassPath(String)
- Does work only when class exists outside a zip or jar file.
-
getDir(String)
- Returns the directory as a string of the given file.
-
getFiles(String)
- Returns a Vector with all files of the given directory.
-
getFiles(String, String)
- Returns a Vector with all file names that are inside the
specified directory.
For example: Util.getFiles("C:\", ".txt")
-
getFilteredDirContent(String, FilenameFilter)
- Returns a Vector with all file names that are inside the
specified directory.
For example: FileUtil.getFiles("C:\", ".txt")
-
getPackagePath(String)
- You give it a package name and it looks with the
help of the classpath on the file system if it can
find a directory that relates to this package.
-
getPackagePath(String, String)
- You give it a package name and it looks with the
help of the classpath on the file system if it can
find a directory that relates to this package.
-
getRecursiveDir(String)
- Be aware that symbolic links might lead to inite loops.
-
getResourceAsStream(Object, String)
- There is one big advantage this method has over
Class.getResourceAsStream(..).
-
getSubDirs(String)
- Liefert einen Vector mit allen Unter-Directories zurück.
-
getSwingHome()
- It searchs in the classpath for swingall.jar, then for
swing.jar and last for com/sun/java/swing on the file
system.
-
getTempDir()
- Returns a temporary directory.
-
getTempFileName()
-
-
isAbsolute(String)
- Tests if the file represented by this File object is an absolute pathname.
-
isFileReadable(String)
- This method checks if it is save to use a file or if e.g.
-
md(String)
- Creates the specified directory and if necessary any parent
directories.
-
move(String, String)
- Renames or moves a file.
-
openFile(String)
-
-
openOutputFile(String)
-
-
printAndWaitUntilQuit()
-
-
readBinaryFile(String)
- Read binary file.
-
readFile(String)
- Reads a File into a String.
-
readFile(URL)
-
-
readStream(InputStream)
- Read a stream, give back a string.
-
writeDosFile(String, String)
-
-
writeFile(String, String)
- Writes a String into a given File.
-
writeFileWithBackup(String, String)
- Writes a String into a given File and does move the old file
if existent to sFileName + ".bak".
S_SWINGALL_JAR
private static final String S_SWINGALL_JAR
S_SWING_JAR
private static final String S_SWING_JAR
FileUtil
public FileUtil()
getPackagePath
public static String getPackagePath(String sPackageName_)
- You give it a package name and it looks with the
help of the classpath on the file system if it can
find a directory that relates to this package.
- Returns:
- Includes the local path of the package too.
If no path could be found, "" is returned.
getPackagePath
public static String getPackagePath(String sPackageName_,
String sClassPath_)
- You give it a package name and it looks with the
help of the classpath on the file system if it can
find a directory that relates to this package.
- Returns:
- Includes the local path of the package too.
If no path could be found, "" is returned.
getClassPath
public static String getClassPath(Object oClass_)
- Does work only when class exists outside a zip or jar file.
- Returns:
- Includes the local path of the package too.
getClassPath
public static String getClassPath(String sFullClassName_)
- Does work only when class exists outside a zip or jar file.
- Returns:
- Includes the local path of the package too.
getSwingHome
public static String getSwingHome()
- It searchs in the classpath for swingall.jar, then for
swing.jar and last for com/sun/java/swing on the file
system. If user renamed the swing archive, we are out
of luck.
- Returns:
- null or "" if swing was not found in the
classpath, otherwise returns the home directory.
It's unspecified if the home dir has a separator
char at the end.
concatPath
public static String concatPath(String sPath_,
String sFile_)
- Concatenates a file path with the file name. If
necessary it adds a File.separator between the path
and file name.
This method is inspired from the FrIJDE project out
of the gCollins.File.FileTools class.
FrIJDE Homepage:
http://amber.wpi.edu/~thethe/Document/Besiex/Java/FrIJDE/
- Parameters:
- sPath_ - must be != null.
- Returns:
- sPath_ if sFile_ is empty.
openFile
public static DataInputStream openFile(String sFile)
openOutputFile
public static DataOutputStream openOutputFile(String sFile)
readStream
public static String readStream(InputStream stream_) throws IOException, FileNotFoundException
- Read a stream, give back a string.
readFile
public static String readFile(String sFileName_) throws IOException, FileNotFoundException
- Reads a File into a String.
readBinaryFile
public static Byte[] readBinaryFile(String sFileName_)
- Read binary file.
readFile
public static String readFile(URL location) throws MalformedURLException, IOException
appendFile
public static void appendFile(String sFileName_,
String sAddedContent_) throws IOException
writeFile
public static void writeFile(String sFileName,
String sContent) throws IOException
- Writes a String into a given File.
writeFileWithBackup
public static void writeFileWithBackup(String sFileName_,
String sContent_) throws IOException
- Writes a String into a given File and does move the old file
if existent to sFileName + ".bak".
- See Also:
- writeFile
writeDosFile
public static void writeDosFile(String sFileName_,
String sContent_) throws IOException
equalsFile
public static boolean equalsFile(String sFileNameA_,
String sFileNameB_)
existsFile
public static boolean existsFile(String sFileName_)
existsDir
public static boolean existsDir(String sDirName_)
- Tests, if a given directory exists.
exists
public static boolean exists(String sFileOrDirName_)
getFilteredDirContent
public static Vector getFilteredDirContent(String sDir_,
FilenameFilter pFilenameFilter_)
- Returns a Vector with all file names that are inside the
specified directory.
For example: FileUtil.getFiles("C:\", ".txt")
- Returns:
- Not the full path names are returned, just the simple
file names.
- See Also:
- getFiles
_getFilteredDirContent
public static Vector _getFilteredDirContent(String sDir_,
FilenameFilter pFilenameFilter_)
- Note: _getFilteredDirContent() is deprecated.
- See Also:
- getFilteredDirContent
getSubDirs
public static Vector getSubDirs(String sDir_)
- Liefert einen Vector mit allen Unter-Directories zurück.
- Returns:
- Es werden nicht die vollen Pfadangaben bei den
Sub-Directories angegeben, sondern nur der einfache
Name.
getFiles
public static Vector getFiles(String sDir_)
- Returns a Vector with all files of the given directory.
- Returns:
- Not the full path names are returned, only the simple
names.
getFiles
public static Vector getFiles(String sDir_,
String sSuffix_)
- Returns a Vector with all file names that are inside the
specified directory.
For example: Util.getFiles("C:\", ".txt")
- Parameters:
- sSuffix_ - A list of suffixes (separated with the
File.pathSeparatorChar) the file names must
match. Otherwise they are not selected.
For example: ".gif;.jpg"
- Returns:
- Not the full path names are returned, just the simple
file names.
equalsPath
public static boolean equalsPath(String sFirstPath_,
String sSecondPath_)
delete
public static boolean delete(String sFileName_)
- Returns:
- true if error.
move
public static boolean move(String sSource_,
String sDest_)
- Renames or moves a file. Be aware that the old file at the
destination will be deleted without a warning.
- Returns:
- true if an error occurred. false if sSource_ is not
existent.
md
public static boolean md(String sFullDirName)
- Creates the specified directory and if necessary any parent
directories.
- Returns:
- true if an error occured. Note that this is vice versa
to the File.mkdirs() behavior.
- See Also:
- mkdirs
getAbsoluteFileName
public static String getAbsoluteFileName(String sFileName_)
- Returns:
- It's the canonical path of sFileName_.
getTempFileName
public static String getTempFileName()
getTempDir
public static String getTempDir()
- Returns a temporary directory. This method will be upwards compatible
to jdk 1.2. It uses the java property "java.io.tempdir". If this is
not set like in jdk 1.1, "user.home" + "/tmp" will be used. If it does
not yet exist we take the freedom to create it. If a $HOME/tmp file
exists already, it will be deleted!!!
isAbsolute
public static boolean isAbsolute(String sFileName_)
- Tests if the file represented by this File object is an absolute pathname. The definition of an absolute pathname is system
dependent. For example, on UNIX, a pathname is absolute if its first character is the separator character. On Windows
platforms, a pathname is absolute if its first character is an ASCII '\' or '/', or if it begins with a letter followed by a colon.
areAllPathsAbsolute
public static boolean areAllPathsAbsolute(String sPathList_)
- Tests if the file represented by this File object is an absolute pathname. The definition of an absolute pathname is system
dependent. For example, on UNIX, a pathname is absolute if its first character is the separator character. On Windows
platforms, a pathname is absolute if its first character is an ASCII '\' or '/', or if it begins with a letter followed by a colon.
getAbsolutePathList
public static String getAbsolutePathList(String sPathList_)
- For example: .;C:\jdk1.1.7\lib\classes.zip
-> C:\java\projects;C:\jdk1.1.7\lib\classes.zip
getRecursiveDir
public static Vector getRecursiveDir(String sFileName_)
- Be aware that symbolic links might lead to inite loops. The
directory itself is always the first element. If
sFileName_ doesn't exist an empty vector is returned.
- Returns:
- Vector with strings of file and directory names.
copyDir
public static boolean copyDir(String sDir_,
String sDestination_)
- Like: cp -r sDir_ sDestination_
No consideration for links are in place, so be aware
of possible infinite loops.
- Returns:
- error
copy
public static boolean copy(String sSourceFile_,
String sDestinationFile_)
- Returns:
- error.
copy
public static boolean copy(InputStream pInputStream_,
OutputStream pOutputStream_)
- Returns:
- error.
copy
public static boolean copy(BufferedInputStream pBufferedInputStream_,
BufferedOutputStream pBufferedOutputStream_)
- Returns:
- error.
getResourceAsStream
public static InputStream getResourceAsStream(Object pObject_,
String sRecourceName_)
- There is one big advantage this method has over
Class.getResourceAsStream(..). There are three
different circumstances from where you want to load
a resource, only two work by the default JDK
ClassLoader resource location method.
First case, your resource file is in the same directory
as your class file just on a normal file system.
Second case, your resource file is inside a jar file.
This both is handled by the normal ClassLoader.
But what if you have a src and a classes directory.
Then you want your resource file in the src directory
tree without the need to copy the resource file over
to the classes directory tree. If you stick to the
'classes' and 'src' directory name convention, this
method still finds the resource in the src directory.
- See Also:
- getResourceAsStream
printAndWaitUntilQuit
public static void printAndWaitUntilQuit()
getDir
public static String getDir(String sFile_)
- Returns the directory as a string of the given file.
isFileReadable
public static boolean isFileReadable(String sFileName_)
- This method checks if it is save to use a file or if e.g. someone else is currently
writing into this file. Warning, this method does not work for ftp. Downloading a
file via ftp and checking if it is readable or not results in true, thought we
want false.
Copied from usenet from Mark Rozas.
All Packages Class Hierarchy This Package Previous Next Index