Monday, 25 April 2016

How to get the file path and absolute path ?


Get the file path and absolute path

Example
File file = File("C:\\folder\\file.txt");

// Get absolute path of file
String absolutePath = file.getAbsolutePath();
System.out.println("Path : " + absolutePath);

// Get file path by substring of absolute path
String filePath = absolutePath.substring(0,             
                     absolutePath.lastIndexOf(File.separator));

System.out.println("File Path : " + filePath);

No comments:

Post a Comment

Note: only a member of this blog may post a comment.