shiami
shiami

Reputation: 7264

How to know the sdcard has enough free size to write in on Android?

I've got the "No space left on device" IOException when writing file. I wish to avoid it happens before writing. How should I do?

Thanks!

Upvotes: 1

Views: 307

Answers (1)

Fred Grott
Fred Grott

Reputation: 3476

from: http://groups.google.com/group/android-developers/browse_thread/thread/ecede996463a4058

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;

Upvotes: 1

Related Questions