Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 why the File.exists() can NOT check the case of the folder name? Thanks!

like image 308
herbertD Avatar asked Jun 28 '11 06:06

herbertD


People also ask

Are file Types case-sensitive?

By default Windows processes treat the file system as case-insensitive. As such they do not differentiate between files or folders based on case.

Are Java files case-sensitive?

Java is a case-sensitive language, which means that the upper or lower case of letters in your Java programs matter.

Are Linux folders case-sensitive?

Linux file system treats file and directory names as case-sensitive. FOO. txt and foo. txt will be treated as distinct files.


1 Answers

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
like image 54
Frxstrem Avatar answered Sep 28 '22 06:09

Frxstrem