Java URI simple path

2003 views java

I just discovered the URI method on JAVA.

But I just want this method to show me a simplified path of a string of a string.

The problem is in the following code:

public static void main (String [] args) throws Exception {
    URI uri = new URI("/a/./b/../../c/");
    System.out.println("Path =" + uri.getPath());

When I execute the code it sends me the whole string and not "/ c", which is the result I'm waiting for.

Thanks in advance for your clarifications :)

answered question

No, it's not necessarily. The code HKX is asking for will normalize the URI, not just return the last item in the path.

1 Answer


According to the JavaDocs,

Normalization is the process of removing unnecessary "." and ".." segments from the path component of a hierarchical URI. Each "." segment is simply removed. A ".." segment is removed only if it is preceded by a non-".." segment. Normalization has no effect upon opaque URIs.

The normalize() method of the URI class should do what you want.

posted this

Have an answer?


Please login first before posting an answer.