Android File.exists() 不区分大小写吗?
我通过以下方式创建了一个新文件夹“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()
无法检查文件夹名称的大小写吗?谢谢!
I've created a new folder "sdcard/dd" by:
File album = new File(albumPath);
if (album.exists()) {
Log.d(TAG, albumPath + " already exists.");
} else {
boolean bFile = album.mkdir();
}
And Again, I create the second folder "sdcard/DD" by the same code, but, this time the album.exists() returns true, which indicates the "dd" is equals "DD".
Anyone know why the File.exists()
can NOT check the case of the folder name? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然 Linux 以及 Android 在文件名方面通常区分大小写,但通常在 SD 卡、记忆棒等上使用的 FAT 文件系统却不区分大小写。因此,Android 在处理这些文件系统上的文件时不会区分情况。
因此,如果您有两个文件,
/sdcard/file
(在 SD 卡上)和/data/file
(在内部文件系统上),您将得到以下结果:While Linux, and therefore also Android, normally is case-sensitive when it comes to filenames, FAT file systems, which are often used on SD cards, memory sticks etc., are case-insensitive. Therefore, Android will not differentiate between cases when it is handling files on these file systems.
So if you have two files,
/sdcard/file
(on the SD card) and/data/file
(on the internal file system), you will get the following results:根据 Android 文档,“Android 支持具有传统存储的设备,传统存储被定义为具有不可变 POSIX 权限类别和模式的不区分大小写的文件系统。”
https://source.android.com/devices/storage/traditional.html
As per Android documentation 'Android supports devices with traditional storage, which is defined to be a case-insensitive filesystem with immutable POSIX permission classes and modes.'
https://source.android.com/devices/storage/traditional.html
文件存在,区分大小写。我不知何故希望你要么没有删除你创建的第一个文件夹(
sdcard/dd
),要么有一些奇怪的 sdcard 文件不区分大小写(它是 FAT,不区分大小写,但是真的不应该重要)。File exists IS case sensitive. I somehow expect you either aren't removing the first folder you created (
sdcard/dd
) or there is some odd sdcard file case-insensitivity (it IS FAT, which isn't case sensitive, but that really shouldn't matter).例如,在 Windows 中尝试此操作。文件名不区分大小写。就像linux的情况一样(android是基于linux的)。浏览目录也被认为不区分大小写。
所以 dd 和 DD 都被识别为相同的路径。
Try this in windows for example. the filename is not case sensitive. as is the case with linux (android being based on linux). navigating through directories also is recognized as case insensitive.
so dd and DD are both recongnized as the same path.
文件可以区分大小写创建,甚至通过 ftp 也可以区分大小写显示,但 contains() 方法不区分。这就是 Android 5.1 上 /storage/emulated/0/somepath 中的情况。我认为这是不一致的行为。
Files can be created case sensitively and are shown case sensitively even via ftp, but the exists() method does not distinguish. This is what it is like here in /storage/emulated/0/somepath on Android 5.1. I think this is inconsistent behaviour.