Java Relative Path Get relativeFileName(final File baseDir, final File file)

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

Description

relative File Name

License

Apache License

Declaration

public static String relativeFileName(final File baseDir, final File file) 

Method Source Code

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

import java.io.File;

public class Main {
    public static String relativeFileName(final File baseDir, final File file) {
        final String basePath = baseDir.getAbsolutePath();
        final String filePath = file.getAbsolutePath();

        if (baseDir.isDirectory() && file.isFile() && filePath.startsWith(basePath)) {
            // +1 to rid of starting '/'
            return filePath.substring(basePath.length() + 1);
        } else {/*from   w  ww .  j  a v a2 s.c o m*/
            return filePath.substring(1);
        }
    }
}

Related

  1. relativeFile(File file, String relativeTo)
  2. relativeFile(Iterable paths, String file)
  3. relativeFrom(File from, File to)
  4. relativePath(File baseDir, File child)
  5. relativePath(File baseDir, File storeFile)
  6. relativePath(File baseDir, File storeFile)