Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * Returns the path for a file.<br> * <code>path("/home/user/test.jpg") == "/home/user"</code><br> * Uses the correct pathSeparator depending on the operating system. On * windows c:/test/ is not c:\test\ * * @param fileName * the name of the file using correct path separators. * @return the path of the file. */ public static String path(final String fileName) { final int sep = fileName.lastIndexOf(File.separatorChar); return fileName.substring(0, sep); } }