Here you can find the source of getPathByTrimmingEndingFileSeparator(URI uri)
"file:/a/b/c" -> "/a/b/c" "file:/a/b/c/" -> "/a/b/c" "file:/a/b/c.txt" -> "/a/b/c.txt"
public static String getPathByTrimmingEndingFileSeparator(URI uri)
//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; } }