Java Path File Name nio relativizePath(Path relativeTo, String filename)

Here you can find the source of relativizePath(Path relativeTo, String filename)

Description

relativize Path

License

Apache License

Declaration

public static String relativizePath(Path relativeTo, String filename) 

Method Source Code


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

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    public static String relativizePath(Path relativeTo, String filename) {
        if (relativeTo == null) {
            return filename;
        }//from w  w w .ja  v a  2s .  c o m

        Path path = getAbsolutePath(filename);
        if (path.startsWith(relativeTo)) {
            return relativeTo.relativize(path).toString();
        } else {
            return path.toString();
        }
    }

    public static Path getAbsolutePath(String name) {
        return Paths.get(name).toAbsolutePath();
    }
}

Related

  1. jobNameFromPath(Path path)
  2. listDocTypeName(Path path)
  3. makeUnique(Path basePath, String baseName)
  4. pathToPackageName(Path path)
  5. readFileFromPath(String filename)
  6. rename(Path origin, Path destination)
  7. renameFile(Path filePath, String postfix)
  8. renameLogFile(Path original)
  9. saveFileFromByteArray(String filename, String pathDirectory, byte[] data)