是不是Android的File.exists()区分大小写? [英] Isn't Android File.exists() case sensitive?

查看:556
本文介绍了是不是Android的File.exists()区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的文件夹SD卡/ DD 的:

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();
}

又一次,我创建了第二个文件夹SD卡/ DD 由同一code,但是,这一次的album.exists()返回true,表示DD是等于DD。

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".

任何人都知道为什么 File.exists()无法检查该文件夹名称的情况下?谢谢!

Anyone know why the File.exists() can NOT check the case of the folder name? Thanks!

推荐答案

尽管Linux,因此也Android的,通常是区分大小写的,当涉及到文件名,FAT文件系统,这往往是SD卡,记忆棒使用等等,不区分大小写。因此,Android将不会案件之间时,它正在处理对这些文件系统文件区分开来。

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.

所以,如果你有两个文件,​​ / SD卡/文件(SD卡上)和 /数据/文件(在内部文件系统),你会得到以下结果:

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:

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

这篇关于是不是Android的File.exists()区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆