I have java.io.File objects A and B, where A represents a directory and B represents a file. B can be an absolute path or a relative path that is 0 or more levels below A. what’s the most efficient way to determine if B is contained by A?
For example,
A is C:\Users\bill\Desktop\abc\xyz123 and B is C:\Users\bob\Documents\inc\data.inc
or
A is C:\Users\bill\Desktop\abc\xyz123 and B is C:\Users\bob\Documents\x1\y1\inc\data.inc
or
A is C:\Users\bill\Desktop\abc\xyz123 and B is ..\..\..\Documents\inc\data.inc
You can check to see if A is the parent of B by doing
Edit: If you want to check if B is one or more levels below A, just keep getting the ParentFile until it’s A or null