public class Path extends Object
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 and Description |
|---|
Path() |
| Modifier and Type | Method and Description |
|---|---|
static String |
changeExtension(String path,
String extension)
Changes the file extension of a filename for a given path.
|
static String |
getDirectoryName(String path)
Returns the directory name for a given path.
|
static String |
getExtension(String path)
Returns the file extension of a filename for a given path.
|
static String |
getFileName(String path)
Returns the file name for a given path.
|
static String |
getFileSeparator()
Returns the file separator character of the current runtime environment.
|
public static String changeExtension(String path, String extension)
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 extensionpublic static String getExtension(String path)
path - The path from which to get the extensionpublic static String getFileName(String 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.
path - The path from which to get the file name. Allowed to be nullpublic static String getDirectoryName(String path)
path - The path from which to get the directory name. Allowed to be nullpublic static String getFileSeparator()
Copyright © 2023. All rights reserved.