the开发者_如何学Gose equal to each other:
new File("c:\\a")
new File("c:\\a\\")
new File("c:\\a","")
new File("c:\\a\\","")
but
new File("c:\\a","\\")
not equals to them
but
new File("c:\\a","\\b")
equals to new File("c:\\a","b")
why?
The JavaDocs for java.io.File
should make this clear.
File(File parent, String child)
Creates a new File instance from a parent abstract pathname and a child pathname string.
File(String pathname)
Creates a new File instance by converting the given pathname string into an abstract pathname.
equals()
- Compares two abstract pathnames lexicographically.
The following prints make it clear, that this have not the same path.
System.out.println(new File("c:\\a").getAbsolutePath());
System.out.println(new File("c:\\a\\").getAbsolutePath());
System.out.println(new File("c:\\a","").getAbsolutePath());
System.out.println(new File("c:\\a\\","").getAbsolutePath());
System.out.println(new File("c:\\a","\\").getAbsolutePath());
System.out.println(new File("c:\\a","\\b").getAbsolutePath());
System.out.println(new File("c:\\a","b").getAbsolutePath());
output
c:\a
c:\a
c:\a
c:\a
c:\a\
c:\a\b
c:\a\b
I know nothing about Java, but isnt it because "c:\a" is a file, and "\" is a directory?
精彩评论