Getting the Parents of a Filename Path

// 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

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.