I would like to check whether an existing file is in a specific directory or a subdirectory of that.
I have two File objects.
File dir; File file; <
I would create a small utility method:
public static boolean isInSubDirectory(File dir, File file) { if (file == null) return false; if (file.equals(dir)) return true; return isInSubDirectory(dir, file.getParentFile()); }