开发者

Isn't Android File.exists() case sensitive?

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 wh开发者_运维百科y the File.exists() can NOT check the case of the folder name? Thanks!


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:

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


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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜