code: public static String getRelativePath(File baseDir, File file){
  		if(!baseDir.isDirectory()){
  			throw new IllegalArgumentException("Base directory must be a directory.");
  		}
  
  		String dirPath = FilenameUtils.normalize(baseDir.getAbsolutePath(), true);
  		String filePath = FilenameUtils.normalize(file.getAbsolutePath(), true);
  		if(!dirPath.endsWith("/")){
  			dirPath += "/";
  		}
  
  		if(filePath.startsWith(dirPath)){
  			return filePath.substring(dirPath.length());
  		}else {
  			throw new IllegalArgumentException("File '" + file + "' not in base directory '" + baseDir + "'");
  		}
  	}
docs: Use {@link java.nio.file.Path#relativize(java.nio.file.Path)} in JDK1.7.
  @param baseDir
  @param file
  @return