In Java, there is no way to include what you want. Maybe there is a library out there somewhere (I can't think of anything out of myself, and Apache Commons IO doesn't seem to have this). You can use this or something like this:
// returns null if file isn't relative to folder public static String getRelativePath(File file, File folder) { String filePath = file.getAbsolutePath(); String folderPath = folder.getAbsolutePath(); if (filePath.startsWith(folderPath)) { return filePath.substring(folderPath.length() + 1); } else { return null; } }
source share