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

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

Description

Strips off the part of the path before the start of the root file.

License

Apache License

Parameter

Parameter Description
file a parameter
root a parameter

Declaration

public static String getRelativePath(File file, File root) 

Method Source Code

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

import java.io.File;

public class Main {
    /**// ww w.  j a v  a 2 s.  c o m
     * Strips off the part of the path before the start of the root file. If the root is c:\temp\foo
     * and the file is c:\temp\foo\folder\file.txt this will return folder\
     * 
     * @param file
     * @param root
     * @return
     */
    public static String getRelativePath(File file, File root) {
        int rootLength = root.getAbsolutePath().length();
        String absolutePath = file.getAbsolutePath();
        String relativePath = absolutePath.substring(rootLength + 1);
        return relativePath;
    }
}

Related

  1. getRelativePath(File file, File basedir)
  2. getRelativePath(File file, File baseDirectory)
  3. getRelativePath(File file, File directory)
  4. getRelativePath(File file, File folder)
  5. getRelativePath(File file, File root)
  6. getRelativePath(File file, File srcDir)
  7. getRelativePath(File file, String xmlDirectoryPath)
  8. getRelativePath(File fileOrFolder, File baseFolder)
  9. getRelativePath(File folderContainingFile, File fileInFolder)