Find parent Directory in java




Read : Create File using createNewFile() method in java file IO





Program to Find parent Directory in java >







import java.io.File;
/** JavaMadeSoEasy.com */
public class FindParentDirectory {
   public static void main(String[] args) {
          String fileName = "c:/myFile.txt";
          File file = new File(fileName);
          System.out.println("Parent directory of " + fileName + " is "+ file.getParent());
   }
}
/*OUTPUT
Parent directory of c:/myFile.txt is c:\
*/


RELATED LINKS>

Find the available filesystem roots in java/ Available disk drives in windows



Execute CMD command through java program >

Execute CMD commands through java program


No comments:

Post a Comment