GetParents

// Get the parent of a relative filename path
File file = new File("Ex1.java");
String parentPath = file.getParent();      // null
File parentDir = file.getParentFile();     // null

// Get the parents of an absolute filename path
file = new File("D:\almanac\Ex1.java");
parentPath = file.getParent();             // D:almanac
parentDir = file.getParentFile();          // D:almanac

parentPath = parentDir.getParent();        // D:
parentDir = parentDir.getParentFile();     // D:

parentPath = parentDir.getParent();        // null
parentDir = parentDir.getParentFile();     // null

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.