Ivo87
Ivo87

Reputation: 11

No space left on device but SD card not full

I have android app which downloads files from google docs to SD card on device. (reason: have PDF-s which I cannot open within app).
It writes successfully to SD card until I get to ~8000th file of 10000 total.

Code for writing to SD:

InputStream is = response.getContent();
FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/"+preferences.getString("username", "manas11")+"/" + tmp_entry.resourceID.replace(":","~_~")+"~_~"+tmp_entry.title));
byte[] buf = new byte[1024];
int len;
while((len=is.read(buf))>0)
    fos.write(buf,0,len);

Exception thrown by line 2:

java.io.FileNotFoundException: /mnt/sdcard/matulic.realestate.hr/file~_~0B3n2EnTf5ATnYTJkNTNmM2QtZDJjYy00YjNhLWJlZjQtYTE4MTU5MjI2N2E5~_~Kuæa Marina Sevid 399.00 m2 - LJETNA AKCIJA IZVRSN - k359.txt (No space left on device)

SD card is microSD™ memory card (SD 2.0 compatible), 8gb, FAT32 formatted. Im using Desire HD.
As you can see filenames are long. I save files to directory in /mnt/sdcard/ which state after exception is (by Astro):
size: 519,668,573 bytes
number of files: 8037
device free size: 4.91 G

Is there any limit for writing to SD I dont know about?
Thank you

Upvotes: 1

Views: 7279

Answers (2)

George Baker
George Baker

Reputation: 1207

I believe this stackoverflow question will answer your question.

Is there a limit for the number of files in a directory on an SD card?

I also checked out some of the information myself and found it basically comes down to a limit in the number of files and the length of the file name. From what I read in the Microsoft document referenced in the link above http://msdn.microsoft.com/en-us/windows/hardware/gg463080.aspx you have a problem with the length of your file names.

First is the length of your file names. Longer file names take up more space. There is a limit of 65,536 32 byte entries in the directory. This is because the maximum size of a directory file container is 2,097,152 bytes (65536*32). However, if your file names are longer than 8.3 they will take up more than just one entry. Also long file names take up more space than simply the sum of their characters. There is overhead to the filesystem that creates things like checksums and a short 8.3 file name to go along with it.

Best advice would be to shorten the file names dramatically and that should solve your problem.

Hope this helps.

Upvotes: 2

dmon
dmon

Reputation: 30168

It might be a limitation of FAT32.

A FAT32 directory can have 65,536 directory entries. Each file and subdirectory takes from two to thirteen entries, depending on the length of its name, so those entries can disappear long before you think you've used them all up. Your total of 22,657 files could very easily use 65,000 entries.

From here.

Have you tried reducing the file name when storing it locally? Does it really have to be that long?

Upvotes: 1

Related Questions