How to check if a given path is possible child of another path?

后端 未结 9 1014
不思量自难忘°
不思量自难忘° 2020-12-09 01:53

I am trying to find if given path is possible child of another path using java. Both path may not exist.

Say c:\\Program Files\\My Company\\test\\My App

9条回答
  •  醉话见心
    2020-12-09 02:00

    File parent = maybeChild.getParentFile();
    while ( parent != null ) {
      if ( parent.equals( possibleParent ) )
        return true;
      parent = parent.getParentFile();
    }
    return false;
    

提交回复
热议问题