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 31 32 33 34 35 36 |
/* Get Absolute path of the file This Java example shows how to get absolute path of a file using getAbsolutePath method of Java File class. */ import java.io.*; public class GetAbsoluteFilePath { public static void main(String[] args) { String filePath = File.separator + "JavaExamples" + File.separator + "IO"; //create new File object File file = new File(filePath); /* * To get absolute path of the file use, * String getAbsolutePath() method of File class. * * It returns a String containing absolute path of the file in filesystem. */ System.out.println("Abstract file path is :" + file.getPath()); System.out.println("Absolute file path is : " + file.getAbsolutePath()); } } /* Output would be Abstract file path is :JavaExamplesIO Absolute file path is : C:JavaExamplesIO */ |
Add Comment