Java Path Create nio createRelativePath(File baseDirFile, File file)

Here you can find the source of createRelativePath(File baseDirFile, File file)

Description

create Relative Path

License

Mozilla Public License

Declaration

public static String createRelativePath(File baseDirFile, File file) throws IOException 

Method Source Code


//package com.java2s;
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

public class Main {

    public static String createRelativePath(File baseDirFile, File file) throws IOException {
        if (baseDirFile == null)
            throw new IllegalArgumentException("baseDirFile must not be null");
        if (file == null)
            throw new IllegalArgumentException("file must not be null");

        Path basePath = baseDirFile.toPath().normalize();
        Path filePath = file.toPath().normalize();

        return basePath.relativize(filePath).toString();
    }// w ww  . j a  va 2  s. co  m

    public static String createRelativePath(String absoluteBaseDirPath, String absoluteFilePath)
            throws IOException {
        if (absoluteBaseDirPath == null)
            throw new IllegalArgumentException("baseDir must not be null");
        if (absoluteFilePath == null)
            throw new IllegalArgumentException("file must not be null");

        return createRelativePath(new File(absoluteBaseDirPath), new File(absoluteFilePath));
    }
}

Related

  1. createPathRelativizer(Path path, boolean doRelativize)
  2. createProperties(final Path directory, final Properties properties)
  3. createRandomClass(String className, Path dir)
  4. createRandomFolder(Path basePath)
  5. createRandomFolders(Path basePath, int numberOfFolders)
  6. createSourceFile(Path path, String... lines)
  7. createSymbolicLink(String linkPathString, String targetPathString)
  8. createSymlink(Path realFileLocation, Path softLinkLocation)
  9. createSymlink(String targetPathStr, File symlinkFile)