1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* Get name of parent directory This Java example shows how to get a name of the parent directory of a particular file or directory using getParent method of Java File class. */ import java.io.*; public class GetParentDirectory { public static void main(String[] args) { //create file object File file = new File("C://FileIO/demo.txt"); /* * To get parent directory of a particular file, use * String getParent() method of Java File class. */ String strParentDirectory = file.getParent(); System.out.println("Parent directory is : " + strParentDirectory); } } /* Output would be Parent directory is : C:FileIO */ |
Add Comment