get Parent Path from a string - Java java.io

Java examples for java.io:Path Name

Description

get Parent Path from a string

Demo Code


//package com.java2s;

public class Main {


    public static String getParentPath(String s) {
        int ind = s.lastIndexOf("/");
        if (ind > 0) {
            return s.substring(0, ind);
        } else {//from w  ww. jav a2s .co m
            if (s.length() > 0) {
                return "";
            } else {
                return null;
            }
        }
    }
}

Related Tutorials