获取sd卡可用空间
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv_free = (TextView) findViewById(R.id.tv_freespace); TextView tv_total = (TextView) findViewById(R.id.tv_totalspace); File storageDirectory = Environment.getExternalStorageDirectory(); long totalSpace = storageDirectory.getTotalSpace(); long freeSpace = storageDirectory.getFreeSpace(); //通过formatter把用byte字节表示的大小 转换成用 kb mb gb 这种单位表示的字符串 String total = Formatter.formatFileSize(this, totalSpace); String free = Formatter.formatFileSize(this, freeSpace); tv_free.setText("剩余空间:"+free); tv_total.setText("总空间:"+total); } }