[fs] Accept Paths.get("/c:/x") on Windows?
Wang Weijun
weijun.wang at oracle.com
Tue Dec 30 14:01:13 UTC 2014
> On Dec 30, 2014, at 16:00, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> On 30/12/2014 04:01, Weijun Wang wrote:
>> new File("/c:/x") return c:\x, but Paths.get() throws an exception
>>
>> java.nio.file.InvalidPathException: Illegal char <:> at index 2: /c:/x
>> at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
>> at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
>> at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
>> at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
>> at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
>> at java.nio.file.Paths.get(Paths.java:84)
>>
>> Is this something that can be fixed?
>>
>> I am asking this because FileURLConnection.getPermission() uses url.getPath() as a file name, and the url was like file:/c:/x.
> InvalidPathException looks correct as the file path is malformed.
>
> In general then you can't use a URL path as file path.
Is Paths.get(url.toURI()) designed for this?
--Max
More information about the nio-dev
mailing list