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

后端 未结 9 945
不思量自难忘°
不思量自难忘° 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:05

    That will probably work fine as it is, although I would use getCanonicalPath() rather than getAbsolutePath(). This should normalize any weird paths like x/../y/z which would otherwise screw up the matching.

提交回复
热议问题