In my android application, I am trying to create the following folder on the sdcard:
/mnt/sdcard/OSGiComponents/admin/felix-cache/
Here's the code:
File cacheDir =
new File( Environment.getExternalStorageDirectory().getAbsolutePath() +
"/OSGiComponents/admin/felix-cache/" );
// Create the folder
cacheDir.mkdirs();
// Check if it exists
if ( ! cacheDir.exists() ) {
Log.e ( "Debug" , "Cache directory cannot be created" );
}
I have the WRITE_STORAGE_PERMISSION under the manifest tag of the android manifest file. I am able to create other folders and files without problem on the sdcard. The app works fine on the following phones:
However on Samsung Galaxy Nexus phone (unrooted) running Ice Cream Sandwich (4.0.4), the directory is created as a zero size file, which can be seen in Astro. The exists() call returns false.
I suspect it is a permissions problem, but I not sure what it is, and why a 0 byte file is created while exists() returns false. Nowhere else in the code am I creating this file.
Any suggestions on what could be the problem?
Thanks :)
UPDATE: I think I have identified the issue, please see the answer I posted.
Zero byte file may be caused by Incompletely file downloading via Web or file transfer protocol client, or incorrectly transmitting email attachment. Save the file with empty content. Corrupted index table in the file system. Computer cannot handle files or folders with extremely long name.
From the Empty Files tab, click Mark all Files and then click Delete Files. Similarly, to delete the 0-byte files in the selected folder tree, click on the Empty Files tab.
A zero-byte file is a file that does not contain any data. While most files contain several bytes, kilobytes (thousands of bytes) or megabytes (millions of bytes) of information, the aptly-named zero-byte file contains zero bytes. Usually a file will contain at least a few bytes.
please use instead of
File cacheDir = new File( Environment.getExternalStorageDirectory().getAbsolutePath() +
"/OSGiComponents/admin/felix-cache/" );
cacheDir.mkdirs();
to
File cacheDir =
new File( Environment.getExternalStorageDirectory().getAbsolutePath() +
"/OSGiComponents/admin/felix-cache" );
cacheDir.mkdir();
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