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 >

Variable Index

 o S_SWING_JAR
 o S_SWINGALL_JAR

Constructor Index

 o FileUtil()

Method Index

 o _getFilteredDirContent(String, FilenameFilter)
Deprecated.
 o appendFile(String, String)
 o areAllPathsAbsolute(String)
Tests if the file represented by this File object is an absolute pathname.
 o concatPath(String, String)
Concatenates a file path with the file name.
 o copy(BufferedInputStream, BufferedOutputStream)
 o copy(InputStream, OutputStream)
 o copy(String, String)
 o copyDir(String, String)
Like: cp -r sDir_ sDestination_ No consideration for links are in place, so be aware of possible infinite loops.
 o delete(String)
 o equalsFile(String, String)
 o equalsPath(String, String)
 o exists(String)
 o existsDir(String)
Tests, if a given directory exists.
 o existsFile(String)
 o getAbsoluteFileName(String)
 o getAbsolutePathList(String)
For example: .;C:\jdk1.1.7\lib\classes.zip -> C:\java\projects;C:\jdk1.1.7\lib\classes.zip
 o getClassPath(Object)
Does work only when class exists outside a zip or jar file.
 o getClassPath(String)
Does work only when class exists outside a zip or jar file.
 o getDir(String)
Returns the directory as a string of the given file.
 o getFiles(String)
Returns a Vector with all files of the given directory.
 o getFiles(String, String)
Returns a Vector with all file names that are inside the specified directory.
For example: Util.getFiles("C:\", ".txt")
 o getFilteredDirContent(String, FilenameFilter)
Returns a Vector with all file names that are inside the specified directory.
For example: FileUtil.getFiles("C:\", ".txt")
 o 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.
 o 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.
 o getRecursiveDir(String)
Be aware that symbolic links might lead to inite loops.
 o getResourceAsStream(Object, String)
There is one big advantage this method has over Class.getResourceAsStream(..).
 o getSubDirs(String)
Liefert einen Vector mit allen Unter-Directories zurück.
 o getSwingHome()
It searchs in the classpath for swingall.jar, then for swing.jar and last for com/sun/java/swing on the file system.
 o getTempDir()
Returns a temporary directory.
 o getTempFileName()
 o isAbsolute(String)
Tests if the file represented by this File object is an absolute pathname.
 o isFileReadable(String)
This method checks if it is save to use a file or if e.g.
 o md(String)
Creates the specified directory and if necessary any parent directories.
 o move(String, String)
Renames or moves a file.
 o openFile(String)
 o openOutputFile(String)
 o printAndWaitUntilQuit()
 o readBinaryFile(String)
Read binary file.
 o readFile(String)
Reads a File into a String.
 o readFile(URL)
 o readStream(InputStream)
Read a stream, give back a string.
 o writeDosFile(String, String)
 o writeFile(String, String)
Writes a String into a given File.
 o writeFileWithBackup(String, String)
Writes a String into a given File and does move the old file if existent to sFileName + ".bak".

Variables

 o S_SWINGALL_JAR
 private static final String S_SWINGALL_JAR
 o S_SWING_JAR
 private static final String S_SWING_JAR

Constructors

 o FileUtil
 public FileUtil()

Methods

 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o openFile
 public static DataInputStream openFile(String sFile)
 o openOutputFile
 public static DataOutputStream openOutputFile(String sFile)
 o readStream
 public static String readStream(InputStream stream_) throws IOException, FileNotFoundException
Read a stream, give back a string.

 o readFile
 public static String readFile(String sFileName_) throws IOException, FileNotFoundException
Reads a File into a String.

 o readBinaryFile
 public static Byte[] readBinaryFile(String sFileName_)
Read binary file.

 o readFile
 public static String readFile(URL location) throws MalformedURLException, IOException
 o appendFile
 public static void appendFile(String sFileName_,
                               String sAddedContent_) throws IOException
 o writeFile
 public static void writeFile(String sFileName,
                              String sContent) throws IOException
Writes a String into a given File.

 o 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
 o writeDosFile
 public static void writeDosFile(String sFileName_,
                                 String sContent_) throws IOException
 o equalsFile
 public static boolean equalsFile(String sFileNameA_,
                                  String sFileNameB_)
 o existsFile
 public static boolean existsFile(String sFileName_)
 o existsDir
 public static boolean existsDir(String sDirName_)
Tests, if a given directory exists.

 o exists
 public static boolean exists(String sFileOrDirName_)
 o 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
 o _getFilteredDirContent
 public static Vector _getFilteredDirContent(String sDir_,
                                             FilenameFilter pFilenameFilter_)
Note: _getFilteredDirContent() is deprecated.

See Also:
getFilteredDirContent
 o 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.
 o 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.
 o 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.
 o equalsPath
 public static boolean equalsPath(String sFirstPath_,
                                  String sSecondPath_)
 o delete
 public static boolean delete(String sFileName_)
Returns:
true if error.
 o 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.
 o 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
 o getAbsoluteFileName
 public static String getAbsoluteFileName(String sFileName_)
Returns:
It's the canonical path of sFileName_.
 o getTempFileName
 public static String getTempFileName()
 o 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!!!

 o 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.

 o 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.

 o 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

 o 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.
 o 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
 o copy
 public static boolean copy(String sSourceFile_,
                            String sDestinationFile_)
Returns:
error.
 o copy
 public static boolean copy(InputStream pInputStream_,
                            OutputStream pOutputStream_)
Returns:
error.
 o copy
 public static boolean copy(BufferedInputStream pBufferedInputStream_,
                            BufferedOutputStream pBufferedOutputStream_)
Returns:
error.
 o 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
 o printAndWaitUntilQuit
 public static void printAndWaitUntilQuit()
 o getDir
 public static String getDir(String sFile_)
Returns the directory as a string of the given file.

 o 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