Java Path File Check nio isDirectoryInPath(File p, File d)

Here you can find the source of isDirectoryInPath(File p, File d)

Description

is Directory In Path

License

LGPL

Declaration

public static boolean isDirectoryInPath(File p, File d) 

Method Source Code


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

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

public class Main {
    public static boolean isDirectoryInPath(File p, File d) {
        try {//from w  ww .  j av  a2  s . c om
            Path p_ = getAbsolutePath(p);
            Path d_ = getAbsolutePath(d);
            return d_.toString().startsWith(p_.toString());
        } catch (NullPointerException | IOException e) {
            return false;
        }
    }

    public static Path getAbsolutePath(File dir) throws IOException {
        return Paths.get(dir.getPath()).toRealPath(LinkOption.NOFOLLOW_LINKS);
    }
}

Related

  1. isDirectory(Path value)
  2. isDirectoryEmpty(Path dir)
  3. isDirectoryEmpty(Path directory)
  4. isDirectoryEmpty(Path path)
  5. isDirectoryEmpty(String dirPath)
  6. isDirEmpty(final Path directory)
  7. isEmpty(Path dir)
  8. isEmptyDir(Path dir)
  9. isEmptyDir(Path path)