Get File Path File Java

Get File Path File Java

Below is sample java program to get absolute file path of existing file including print its parent directory name:

  • GetFilePath.java:
package com.javahonk;

import java.io.File;

public class GetFilePath {

	public static void main(String[] args) {
		
		File file = new File("C:\\JavaHonk\\FileReadFile.txt");
		System.out.println("Absolute path name: "+file.getAbsolutePath());
		System.out.println("Abstract path name: "+file.getPath());
		System.out.println("Praent directory name: "+file.getParent());
		System.out.println("Abstract path name Praent: "+file.getParentFile());

	}

}
  • Output:

Get File Path File Java

  •  For more information about File API please refer oracle documentation here

Leave a Reply

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