I am getting following error when trying to save to external cache dir (SD card) :
java.io.FileNotFoundException:
/mnt/sdcard/Android/data/myapp/cache/files/filenamexxx.png?1385609534:
open failed: EINVAL (Invalid argument) file:filenamexxx.png?1385609534
Using following code:
File sdCard = ctx.getExternalCacheDir();
File dir = new File(sdCard.getAbsolutePath() + "/files/");
dir.mkdirs();
File file = new File(dir, mFileName);
fos = new FileOutputStream(file);
fos.write ....
But saving to device when no SD card found works fine:
fos = ctx.openFileOutput(mFileName, Context.MODE_PRIVATE);
fos.write ....
Does the ?1385609534 in the file name end mess it up, when trying to save into SD cache?
Thanks.
Some filesystems dont allow certain characters. You can check out which filesystem cant use which character here: Link
In your case it is most likely FAT32, so:
Any byte except for values 0-31, 127 (DEL) and: " * / : < > ? \ | + , . ; = [] (lowcase a-z are stored as A-Z). With VFAT LFN any Unicode except NUL
I ended up replacing all illegal characters:
mFileName = mFileName.replaceAll("[|?*<\":>+\\[\\]/']", "_");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With