开发者

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

开发者 https://www.devze.com 2023-01-25 18:09 出处:网络
I\'ve got th开发者_如何学Goe \"No space left on device\" IOException when writing file. I wish to avoid it happens before writing.

I've got th开发者_如何学Goe "No space left on device" IOException when writing file. I wish to avoid it happens before writing. How should I do?

Thanks!


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消