A DESCRIPTION OF THE REQUEST :
As documented in http://docs.oracle.com/javase/8/docs/api/java/io/File.html#isAbsolute-- , the isAbsolute function:
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\".
However, Windows accepts both forward and backward slash as prefix, as documented in:
https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#fully_qualified_vs._relative_paths
JUSTIFICATION :
Using / as the root directory makes Java applications even more cross-platform, given that the code would not need to cares about the drive letter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After using:
File source=new File("/foo.bar")
The instruction source.isAbsolute() would return true also on Windows.
ACTUAL -
After using:
File source=new File("/foo.bar")
The instruction source.isAbsolute() returns false.
---------- BEGIN SOURCE ----------
import java.io.File;
public class test {
public static void main(String[] args) {
final String path = "/foo.bar";
File source = new File( path );
if (source.isAbsolute())
{
System.out.println(path+" IS an absolute path!");
} else
{
System.out.println(path+" is not an absolute path!");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.io.File;
public class test {
public static void main(String[] args) {
final String path = "/foo.bar";
File source = new File( path );
if (source.isAbsolute() || source.getPath().charAt(0) == "/" || source.getPath().charAt(0) == "\\")
{
System.out.println(path+" IS an absolute path!");
} else
{
System.out.println(path+" is not an absolute path!");
}
}
}
As documented in http://docs.oracle.com/javase/8/docs/api/java/io/File.html#isAbsolute-- , the isAbsolute function:
Tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent. On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\".
However, Windows accepts both forward and backward slash as prefix, as documented in:
https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#fully_qualified_vs._relative_paths
JUSTIFICATION :
Using / as the root directory makes Java applications even more cross-platform, given that the code would not need to cares about the drive letter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After using:
File source=new File("/foo.bar")
The instruction source.isAbsolute() would return true also on Windows.
ACTUAL -
After using:
File source=new File("/foo.bar")
The instruction source.isAbsolute() returns false.
---------- BEGIN SOURCE ----------
import java.io.File;
public class test {
public static void main(String[] args) {
final String path = "/foo.bar";
File source = new File( path );
if (source.isAbsolute())
{
System.out.println(path+" IS an absolute path!");
} else
{
System.out.println(path+" is not an absolute path!");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
import java.io.File;
public class test {
public static void main(String[] args) {
final String path = "/foo.bar";
File source = new File( path );
if (source.isAbsolute() || source.getPath().charAt(0) == "/" || source.getPath().charAt(0) == "\\")
{
System.out.println(path+" IS an absolute path!");
} else
{
System.out.println(path+" is not an absolute path!");
}
}
}
- relates to
-
JDK-8189953 FileHandler constructor throws NoSuchFileException with absolute path
-
- Resolved
-