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

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

Description

gets the relative path of a file.

License

Apache License

Parameter

Parameter Description
root the root path to get relative from.
file the file to get the relative path of.

Return

the relative path of the file.

Declaration

public static String getRelativePath(File root, File file) 

Method Source Code

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

import java.io.File;

public class Main {
    /**//from www.  ja  va2s.  co  m
     * gets the relative path of a file.
     * @param root the root path to get relative from.
     * @param file the file to get the relative path of.
     * @return the relative path of the file.
     */
    public static String getRelativePath(File root, File file) {
        String rel = file.getAbsolutePath().substring(
                root.getAbsolutePath().length() + 1);
        rel = rel.replaceAll("\\\\", "/");
        return rel;
    }
}

Related

  1. getRelativePath(File parent, File f)
  2. getRelativePath(File parentDirectory, File file)
  3. getRelativePath(File path, File base)
  4. getRelativePath(File path, File basePath)
  5. getRelativePath(File ref_file, File tst_file)
  6. getRelativePath(File root, File file)
  7. getRelativePath(File root, File target, String fileSeparator)
  8. getRelativePath(File rootDirectory, File file)
  9. getRelativePath(File source, File destination)