Here you can find the source of pathContains(String root, String child)
Parameter | Description |
---|---|
root | The root path |
child | The child path we are checking against |
public static boolean pathContains(String root, String child)
//package com.java2s; //License from project: Open Source License import com.google.common.io.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { /**//w ww. j a va2 s. co m * Verifies that a path, <i>child</i>, is inside of a parent path <i>root</i> * * @param root The root path * @param child The child path we are checking against * @return false if the child path exists outside of the root path, true otherwise */ public static boolean pathContains(String root, String child) { Path childPath = Paths.get(Files.simplifyPath(child)); Path rootPath = Paths.get(root); return childPath.startsWith(rootPath); } }