Java URI to Path getPathByTrimmingEndingFileSeparator(URI uri)

Here you can find the source of getPathByTrimmingEndingFileSeparator(URI uri)

Description

Trim eventual ending File#separator .
Ex:
 "file:/a/b/c" -> "/a/b/c" "file:/a/b/c/" -> "/a/b/c" "file:/a/b/c.txt" -> "/a/b/c.txt" 

License

Apache License

Declaration

public static String getPathByTrimmingEndingFileSeparator(URI uri) 

Method Source Code


//package com.java2s;
// Splunk Inc. licenses this file

import java.io.File;
import java.net.URI;

public class Main {
    /**//w  w w  .  ja  v  a  2 s  .  c om
     * Trim eventual ending {@link File#separator}.<br/>
     * Ex:<br/>
     * 
     * <pre>
     * "file:/a/b/c" -> "/a/b/c"
     * "file:/a/b/c/" -> "/a/b/c"
     * "file:/a/b/c.txt" -> "/a/b/c.txt"
     * </pre>
     */
    public static String getPathByTrimmingEndingFileSeparator(URI uri) {
        String path = uri.getPath();
        if (path.endsWith(File.separator))
            return path.substring(0, path.length() - 1);
        else
            return path;
    }
}

Related

  1. getPath(String uriStr)
  2. getPath(URI addr)
  3. getPath(URI uri)
  4. getPathAndQueryURI(URI requestUri)
  5. getPathAsArray(URI uri)
  6. getPathComponents(URI uri)
  7. getPathParamValue(URI uri)
  8. getPathSegments(URI uri)