Java tutorial
//package com.java2s; public class Main { public static String getDirectory(String iPath) { iPath = getPath(iPath); int pos = iPath.lastIndexOf("/"); if (pos == -1) return ""; return iPath.substring(0, pos); } public static String getPath(final String iPath) { if (iPath == null) return null; return iPath.replace('\\', '/'); } }