不是Android File.exists()区分大小写?

前端之家收集整理的这篇文章主要介绍了不是Android File.exists()区分大小写?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我已经创建了一个新的文件夹“sdcard / dd”:
File album = new File(albumPath);

if (album.exists()) {
   Log.d(TAG,albumPath + " already exists.");
} else {
   boolean bFile = album.mkdir();
}

而且,我创建第二个文件夹“sdcard / DD”由相同的代码,但是,这次album.exists()返回true,这表示“dd”是等于“DD”.

任何人都知道为什么File.exists()不能检查文件名称的大小写?谢谢!

解决方法

虽然Linux,因此也是Android,通常在文件名时是区分大小写的,通常在SD卡,记忆棒等上使用的FAT文件系统是不区分大小写的.因此,当它处理这些文件系统上的文件时,Android将不会区分这些情况.

因此,如果您有两个文件,/ sdcard / file(SD卡)和/ data / file(在内部文件系统上),您将得到以下结果:

new File("/sdcard/file").exists(); // true
new File("/sdcard/FILE").exists(); // true,/sdcard is a case-insensitive file system
new File("/data/file").exists(); // true
new File("/data/FILE").exists(); // false,/data is a case-sensitive file system
原文链接:https://www.f2er.com/android/312618.html

猜你在找的Android相关文章