Class Path
- java.lang.Object
-
- com.gurock.smartinspect.Path
-
public class Path extends Object
Provides static methods to perform certain operations on strings which represent a path.The Path class provides several methods to perform transformations on path strings. This class only transforms strings and does no operations on the corresponding filesystem entries. For example, the changeExtension method changes the extension of a given path string but does not change the actual filesystem entry. Operations are done in a cross-platform manner.
This class is not guaranteed to be threadsafe.
-
-
Constructor Summary
Constructors Constructor Description Path()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringchangeExtension(String path, String extension)Changes the file extension of a filename for a given path.static StringgetDirectoryName(String path)Returns the directory name for a given path.static StringgetExtension(String path)Returns the file extension of a filename for a given path.static StringgetFileName(String path)Returns the file name for a given path.static StringgetFileSeparator()Returns the file separator character of the current runtime environment.
-
-
-
Method Detail
-
changeExtension
public static String changeExtension(String path, String extension)
Changes the file extension of a filename for a given path. If the supplied path argument is null, the return value of this method is null as well. If the supplied extension argument is null or an empty string, an existing file extension is removed from the given path.- Parameters:
path- The path information to modify. Allowed to be nullextension- The file extension (with leading period). Specify null or an empty string to remove an existing file extension- Returns:
- The supplied path but with the changed or removed extension
-
getExtension
public static String getExtension(String path)
Returns the file extension of a filename for a given path. This method returns the file extension of the given path string including the leading period character. If the supplied path parameter is a null reference or does not contain an extension, the return value of this method is an empty string.- Parameters:
path- The path from which to get the extension- Returns:
- The file extension of the supplied path if available or an empty string otherwise
-
getFileName
public static String getFileName(String path)
Returns the file name for a given path.This method returns the file name of the given path string excluding any directory or volume separator characters. If the supplied path parameter is a null reference, the return value of this method is null as well. If the last character of the supplied path argument is a directory or volume character, then the return value of this method is an empty string.
- Parameters:
path- The path from which to get the file name. Allowed to be null- Returns:
- The file name of the supplied path if available or null if the supplied path argument is null
-
getDirectoryName
public static String getDirectoryName(String path)
Returns the directory name for a given path. This method returns the directory name of the given path string. If the supplied path parameter is a null reference, the return value of this method is null as well.- Parameters:
path- The path from which to get the directory name. Allowed to be null- Returns:
- The directory of the supplied path if available or null if the supplied path argument is null
-
getFileSeparator
public static String getFileSeparator()
Returns the file separator character of the current runtime environment.- Returns:
- The file separator of the current runtime environment
-
-