You can use the following static method:
/**
* <p>
* Checks, whether the provided path points to a case-sensitive file system or not.
* </p>
* <p>
* It does so by creating two temp-files in the provided path and comparing them. Note that you need to have write
* access to the provided path.
*
* @param pathToFileSystem path to the file system to test
* @param tmpFileName name of the temp file that is created
* @return {@code true}, if the provided path points to a case-sensitive file system; {@code false} otherwise
* @throws IOException if IO operation fails
*/
public static boolean fileSystemIsCaseSensitive(Path pathToFileSystem, String tmpFileName) throws IOException {
Path a = Files.createFile(pathToFileSystem.resolve(Paths.get(tmpFileName.toLowerCase())));
Path b = null;
try {
b = Files.createFile(pathToFileSystem.resolve(Paths.get(tmpFileName.toUpperCase())));
} catch (FileAlreadyExistsException e) {
return false;
} finally {
Files.deleteIfExists(a);
if (b != null) Files.deleteIfExists(b);
}
return true;
}
Use it as follows:
@Test
void fileSystemIsCaseSensitive01() throws IOException {
assertTrue(Util.fileSystemIsCaseSensitive(Paths.get("/Volumes/Case-sensitive-Volume/Data"), "a"));
}
@Test
void fileSystemIsCaseSensitive02() throws IOException {
assertFalse(Util.fileSystemIsCaseSensitive(Paths.get("/Volumes/Case-insensitive-Volume/Data"), "a"));
}
Note the different volumes provided (Case-sensitive-Volume vs. Case-insensitve-Volume).