Java Path Relative Get getRelativePath(File baseDir, File subFile, String seperator)

Here you can find the source of getRelativePath(File baseDir, File subFile, String seperator)

Description

get Relative Path

License

Apache License

Declaration

public static String getRelativePath(File baseDir, File subFile, String seperator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {

    public static String getRelativePath(File baseDir, File subFile, String seperator) {
        String basePath = baseDir.getAbsolutePath();
        String filePath = subFile.getAbsolutePath();
        if (!filePath.startsWith(basePath)) {
            return null;
        }//from  w ww  .  j a  va2s . com
        String relativePath = filePath.substring(basePath.length() + 1);
        return seperator == null ? relativePath
                : relativePath.replaceAll("\\\\", seperator).replaceAll("/", seperator);
    }

    public static String getRelativePath(File baseDir, File file) {
        return getRelativePath(baseDir, file, null);
    }
}

Related

  1. getRelativePath(File base, File target)
  2. getRelativePath(File baseDir, File file)
  3. getRelativePath(File baseDir, File file)
  4. getRelativePath(File baseDir, File file)
  5. getRelativePath(File baseDir, File file)
  6. getRelativePath(File baseFile, File file)
  7. getRelativePath(File baseFolder, File subject)
  8. getRelativePath(File child, File directory)
  9. getRelativePath(File currentDir, File target)