java.io.File(parent, child) does not work as expected

If the child pathname string is absolute then it is converted into a relative pathname in a system-dependent way.

I assume this means that even if you provide an absolute path, it will be converted to (in a system dependent way), and treated as, a relative path.

Which means I have to figure out the exact relative path (or at least test different options to see if the file exists).

Yes, I believe so.

This could perhaps be easily done with

file.getAbsolutePath().startsWith(parent.getAbsolutePath());

to check if it is an absolute path to a directory in parent, and

file.getAbsolutePath().substring(parent.getAbsolutePath().length());

to get the relative part.

Tags:

Java

Io

File