Java Utililty Methods Parent Path Get

List of utility methods to do Parent Path Get

Description

The list of methods to do Parent Path Get are organized into topic(s).

Method

StringgetParentPath()
get the parent directory of the current directory
try {
    return new File("..").getCanonicalPath();
} catch (IOException ioe) {
    throw new IllegalStateException(ioe);
StringgetParentPath(File file, boolean wrap, boolean escape)
get Parent Path
if (file.getParent() != null) {
    return wrapAndEscape(file.getParentFile().getAbsolutePath(), wrap, escape);
} else {
    return null;
StringgetParentPath(String absolutePath)
get Parent Path
if (!isExist(absolutePath)) {
    return null;
File file = new File(absolutePath);
return file.getParent();
StringgetParentPath(String filePath)
Returns only the parent directory path of the given file path, e.g.
return filePath.substring(0, filePath.lastIndexOf(File.separatorChar) + 1);
StringgetParentPath(String fullpath)
get Parent Path
File file = new File(fullpath);
if (file == null) {
    return "";
if (file.getParentFile() == null) {
    return "";
return file.getParentFile().getPath();
...
StringgetParentPath(String path)
get Parent Path
return new File(path).getParent();
StringgetParentPath(String path)
Convenience method to get the Path to the folder containing the file or directory in the supplied path.
try {
    return new File(path).getParent();
} catch (Exception e) {
    e.printStackTrace();
return null;
StringgetParentPathAndName(String path, StringBuilder parent)
get Parent Path And Name
final int len = path.length();
final char sep = File.separatorChar;
int end = 0;
for (int i = 0; i < len; i++) {
    char ch = path.charAt(i);
    if (ch == sep) {
        ch = '/';
        end = i;
...
StringgetParentPathname(String pathname)
Returns the parent of pathname
return getAncestorPathname(pathname, 1);