Skip to content

Calling Path.toUri() on a directory should return a URI with a trailing slash #16

@seanrohead

Description

@seanrohead

The default file system provider returns URI's with trailing slashes if the URI is known to refer to a directory. This only way to know for sure if a URI refers to a directory or a file is if the directory actually exists on disk. For example:

    Path rootPath = Paths.get(URI.create("file:/"));
    System.out.println(rootPath.toUri());
    Path dir1 = rootPath.resolve("dir1");
    System.out.println(dir1.toUri());
    Path dir1Path = Files.createDirectory(dir1);
    System.out.println(dir1.toUri());
    System.out.println(dir1Path.toUri());

If C:\dir1\ does not exist before running this code, the result will be:

file:///C:/
file:///C:/dir1
file:///C:/dir1/
file:///C:/dir1/

Notice that dir1.toUri() does not contain a trailing slash before the directory is created, but it does contain a trailing slash afterward.

I have verified this same behavior on OSX as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions