File.exists() 對大小寫敏感與否由底層文件系統決定,非 Java/API 行為。
| 存儲位置 | 文件系統 | 大小寫敏感 | 示例 |
|---|---|---|---|
| SD 卡 | FAT32 / exFAT | 不敏感 | /sdcard/dd == /sdcard/DD |
| 內部存儲 | ext4 / f2fs | 敏感 | /data/file != /data/FILE |
new File("/sdcard/file").exists(); // true
new File("/sdcard/FILE").exists(); // true (FAT32 不敏感)
new File("/data/file").exists(); // true
new File("/data/FILE").exists(); // false (ext4 敏感)
File dir = new File("/sdcard");
String[] files = dir.list();
for (String f : files) {
if (f.equalsIgnoreCase("dd")) { // 邏輯層面忽略大小寫
// 找到
}
}
知曉文件系統特性,路徑大小寫處理不再踩坑。