import java.io.File; public class GetFilePath { public static void main(String args[]){ File file = new File("C:\\work\\hello\\helloworld.txt"); System.out.println("The file path is " + file.getAbsolutePath()); String path = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(File.separator)); System.out.println("The abs path is " + path); } }