net.sourceforge.cobertura.javancss
Class FileUtil
java.lang.Object
net.sourceforge.cobertura.javancss.FileUtil
Utility class for file operations.
Simple but most commonly used methods of this class are:
-
readFile
-
concatPath
Other less frequently used but still handy methods are:
-
normalizeFileName
to take the current user directory into account via the 'user.dir' system property
$Id: FileUtil.java 384 2006-03-17 20:10:49Z thekingant $FileUtil() - Utility class which should never instanciate itself.
|
private static String | concatPath(String sPath_, String sFile_) - Concatenates a file path with the file name.
|
private static String | getAbsoluteFileName(String sFileName_)
|
private static boolean | isAbsolute(String sFileName_) - Tests if the file represented by this File object is an absolute
pathname.
|
static String | normalizeFileName(String sFile) - This method returns an absolute (canonical)
file name.
|
private static String | normalizeFileName(String sFile, String sUserDir) - This method returns an absolute (canonical)
file name.
|
static String | readFile(String sFileName_) - Reads a File and returns the content in a String.
|
FileUtil
private FileUtil()
Utility class which should never instanciate itself.
concatPath
private 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. For example "/home" or "/home/" and "clemens" both
become "/home/clemens".
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/
sPath_
- a directory path. Is not allowed to be null.sFile_
- the base name of a file.
- sPath_ if sFile_ is empty.
getAbsoluteFileName
private static String getAbsoluteFileName(String sFileName_)
- It's the canonical path of sFileName_.
isAbsolute
private 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.
normalizeFileName
public static String normalizeFileName(String sFile)
This method returns an absolute (canonical)
file name. The difference to getAbsoluteFileName
is that this method uses the system property
"user.dir" instead of the native system's current
directory. This way you get a chance of changing
the current directory inside Java and let your
program reflect that change.
normalizeFileName
private static String normalizeFileName(String sFile,
String sUserDir)
This method returns an absolute (canonical)
file name. The difference to getAbsoluteFileName
is that this method uses the system property
sUserDir instead of the native system's current
directory. This way you get a chance of changing
the current directory inside Java and let your
program reflect that change.
readFile
public static String readFile(String sFileName_)
throws IOException,
FileNotFoundException
Reads a File and returns the content in a String.
CRLF -> LF conversion takes place. This is a convenience method so you don't
need to bother creating a file reader object and closing it after it has
been used.
sFileName_
- the name of the file to read.
- a string with the content of the file but without
any CR characters.