Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File.getCanonicalPath  RSS feed

 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to save the file path in a String which do i use. This should be system independent
String temp=file.getAbsolutePath();
String temp1=file.getCanonicalPath();
Both of these almost return the same results then what is the difference.

 
GANDHI RAMANATHAN
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Rahul
By reading this example you can know difference between absolutepath and canonical path
Assume that you have a text file in c:\windows\jcp\file1.txt,you
compile and run the file in d:\somename\some>
File f=new File("../jcp/file1.txt");
System.out.println("ab path"+f.getAbsolutePath());//this will return d:\somename\some..\jcp\file1.txt
System.out.println("ca path"+f.getCanaonicalPath());//this will
return d:\somename\jcp\file1.txt
if u give like this
File f1=new File("file.txt")both the answers will be same.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it Gandhi!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!