判断SD卡是否还有足够的空间以便写文件

public boolean isEnoughSpaceInSDcard(long fileSize) {
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			long avaliableSize = 0;
			String storageDirectory = null;
			storageDirectory = Environment.getExternalStorageDirectory()
					.getAbsolutePath();

			LogUtil.d("erik", "getAvailableStorage. storageDirectory : "
					+ storageDirectory);

			try {
				StatFs stat = new StatFs(storageDirectory);
				avaliableSize = ((long) stat.getAvailableBlocks() * (long) stat
						.getBlockSize());
				LogUtil.d("erik", "getAvailableStorage. avaliableSize : "
						+ avaliableSize);

			} catch (RuntimeException ex) {
				return false;
			}

			return avaliableSize > fileSize;
		} else {
			return false;
		}
	}
 

你可能感兴趣的:(Android)