normalize Path - Java java.io

Java examples for java.io:Path Name

Description

normalize Path

Demo Code


//package com.java2s;

public class Main {


    public static String normalizePath(String path) {
        return normalizePath(path, false);
    }//from w w  w  . j a  v  a2s  .  c o m

    public static String normalizePath(String path, boolean absolute) {
        path = path.trim();
        if (path.startsWith("/")) {
            if (!absolute) {
                path = path.substring(1);
            }
        } else {
            if (absolute) {
                path = "/" + path;
            }
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        return path;
    }
}

Related Tutorials