Is this a bug in java jdk?

Viewed 445

When I got a java.lang.File class with the code File file = new File("e:/");, of course I got a File class represented the e:\ directory.

But if I got a File class with code File file = new File("e:"); and I just in the drive E:, then I got a File class represented current directory.

Assume I'm in directory E:\dir\, And this directory have a file named Test.java. It's content is:

import java.io.File;
public class Test {
    public static void main(String[] args) {
        File file = new File("e:"); 
        File[] files = file.listFiles(); 
        for(File f: files){ 
            System.out.println(f + " " + f.exists()); 
        }
    }
}

Open the cmd tool and navigate to the directory e:\dir, execute the following command in it:

E:\dir> javac Test.java
E:\dir> java Test

I got:

e:\Test.class false
e:\Test.java false

Is this a java jdk bug?


Additional information from @JimGarrison:

I ran this code

public class Foo3
{
    public static void main(String[] args)  throws Exception
    {
        File f = new File("D:");
        System.out.println(f.getCanonicalPath());
        for (File x : f.listFiles())
            System.out.println(x + " " + x.getCanonicalPath() + " " + x.getAbsolutePath() + " " + x.exists() + " " + x.getAbsoluteFile().exists());
    }
}

in Eclipse (which lives on my D: drive) and got the following output:

D:\dev\src\pdxep
D:\.classpath D:\dev\src\pdxep\.classpath D:\dev\src\pdxep\.classpath false true
D:\.project D:\dev\src\pdxep\.project D:\dev\src\pdxep\.project false true
D:\.settings D:\dev\src\pdxep\.settings D:\dev\src\pdxep\.settings false true
D:\gallery D:\dev\src\pdxep\gallery D:\dev\src\pdxep\gallery false true
D:\pom.xml D:\dev\src\pdxep\pom.xml D:\dev\src\pdxep\pom.xml false true
D:\src D:\dev\src\pdxep\src D:\dev\src\pdxep\src false true
D:\target D:\dev\src\pdxep\target D:\dev\src\pdxep\target false true

Which confirms there's something funny going on.

Java Bug 8130462 seems to be related as it has to do with relative vs absolute paths specifically in Windows.

2 Answers
Related