Java Path Relative Get getRelativePath(File baseDir, File file)

Here you can find the source of getRelativePath(File baseDir, File file)

Description

get Relative Path

License

Open Source License

Declaration

public static String getRelativePath(File baseDir, File file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static String getRelativePath(File baseDir, File file) {
        String basePath = baseDir.getAbsolutePath();
        if (!basePath.endsWith(File.separator)) {
            basePath += File.separator;
        }//from   www . j  ava  2  s. co  m

        String filePath = file.getAbsolutePath();
        if (!filePath.startsWith(basePath)) {
            throw new IllegalArgumentException("Not dir-relative: " + filePath + " vs " + basePath);
        }

        String relativePath = filePath.substring(basePath.length());
        return relativePath;
    }
}

Related

  1. getRelativePath(File base, File path)
  2. getRelativePath(File base, File path)
  3. getRelativePath(File base, File target)
  4. getRelativePath(File baseDir, File file)
  5. getRelativePath(File baseDir, File file)
  6. getRelativePath(File baseDir, File file)
  7. getRelativePath(File baseDir, File subFile, String seperator)
  8. getRelativePath(File baseFile, File file)
  9. getRelativePath(File baseFolder, File subject)