|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.sfac.file.FilePathUtils
public class FilePathUtils
Utilities to manipulate file paths as strings.
In particular it can convert absolute to relative paths (and vice-versa). This utility class is quite platform-independent
beacuse it handles indifferently slash or backslash as path separator. The only platform-specific thing is that it ignores case
in path comparison (wich is mandatory on Windows system), this is detected fom the file system or can be passed as a constructor
parameter.
| Constructor Summary | |
|---|---|
FilePathUtils(File baseDir)
Create a FilePathUtils bounded to the given local base directory. |
|
FilePathUtils(String basePath,
boolean ignoreCaseInPaths)
Create a FilePathUtils bounded to the given base directory. |
|
| Method Summary | |
|---|---|
String |
canonicalize(String originalPath)
Canonicalize the given path. |
static String |
concatPaths(String firstPath,
String secondPath)
Concatenate two paths to one path. |
String |
getAbsoluteFilePath(String filePath)
Get an absolute file path for the given path. |
String |
getBasePath()
Get the base path used a starting point for relative paths. |
static String |
getDirectoryPath(String filePath)
Get the directory part of a full file path. |
static String |
getDrive(String filePath)
Get the drive of a path or null if no drive is specified in the path. |
static String |
getExtension(String fileName)
Get the extension of the given file (ex: extension of "myIcon.gif" returns "gif"). |
static String |
getFileName(String filePath)
Get the file name (and extension) from the gievn path. |
String |
getRelativeFilePath(String filePath)
Get the given path expressed as relative to this class base directory (if possible). |
char |
getSparatorChar()
Get the preferred file separator char ('/' or '\') of this FilePathUtils. |
static boolean |
isAbsolute(String filePath)
Check if the given file path is absolute. |
static boolean |
startsWithSlash(String filePath)
Check if the given file path start with a separator (usually slash or backslash). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FilePathUtils(File baseDir)
baseDir - The base directory used a starting point for relative paths.
IllegalArgumentException - if the given base directory is not a directory of cannot be canonicalised.
public FilePathUtils(String basePath,
boolean ignoreCaseInPaths)
basePath - The canonicalized base path (with the drive if present). This class will use (when creating paths) the path
separator given in this base reference path.ignoreCase - true if the target file system is not case sensitive.
IllegalArgumentException - if the given base directory cannot be canonicalised.| Method Detail |
|---|
public char getSparatorChar()
public String getBasePath()
public String getAbsoluteFilePath(String filePath)
throws InvalidPathException
filePath - the file path to make absolute.
InvalidPathException - if the given path can not be combined with the base path to produce a canonicalised path.
public String canonicalize(String originalPath)
throws InvalidPathException
originalPath - a path to canonicalize.
InvalidPathException - If the path cannot be canonicalized for any reason.
public String getRelativeFilePath(String filePath)
throws InvalidPathException
filePath - The path to express as relative to this class base directory.
InvalidPathExceptionpublic static boolean isAbsolute(String filePath)
filePath - the file path to check
public static boolean startsWithSlash(String filePath)
filePath - the file path to check
public static String getDrive(String filePath)
filePath - The file path possibly starting with a drive letter.
public static String concatPaths(String firstPath,
String secondPath)
firstPath - first path to concatenate.secondPath - second path to concatenate.
public static String getExtension(String fileName)
fileName - a file name
public static String getDirectoryPath(String filePath)
Note: This method does not try to interpret the path, the last item of the path is assumed to be a file name (even if it is a directory). So directory for "\Temp\test" is "\Temp", and directory for "\Temp\" is "\Temp".
filePath - a full file pathpublic static String getFileName(String filePath)
Note: This method does not try to interpret the path, the last item of the path is assumed to be a file name (even if it is a directory). So file name for "\Temp\test" is "test", and file name for "\Temp\" is "".
filePath - a full file path
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||