Here you can find the source of getRelativePath(File file)
private static String getRelativePath(File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { private static String getRelativePath(File file) throws IOException { String curPath = new File(".").getCanonicalPath(); String targetPath = file.getCanonicalPath(); return targetPath.substring(curPath.length() + 1); }//from w w w.j av a 2 s .c om }