获取机身存储路径(可以通过openFileInput,openFileOutput进行操作)

String path=Environment.getDataDirectory().getAbsolutePath();返回/data

获取内置SD卡路径:

public String getStorageDir(){     if(!(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))){     return "";     }     File dirFile=Environment.getExternalStorageDirectory();     Log.d(TAG, dirFile.getAbsolutePath());     return dirFile.getAbsolutePath();    }

返回/storage/emulated/o

获取外置TF卡路径:

思路:通过linux中的mount命令。

public String getTFDir(){String path="";try {InputStream ins=Runtime.getRuntime().exec("mount").getInputStream();BufferedReader reader=new BufferedReader(new InputStreamReader(ins));String line="";while((line=reader.readLine())!=null){if(line.contains("sdcard")){if(line.contains("vfat")||line.contains("fuse")){String split[]=line.split(" ");path=split[1];Log.d(TAG,path);}}}reader.close();ins.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{}return path;}
返回/storage/sdcard1这就是我们想要的路径。

获取可用空间

public static long getAvailableSize(String path){    try{        File base = new File(path);    StatFs stat = new StatFs(base.getPath());    long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks());    return nAvailableCount;    }catch(Exception e){    e.printStackTrace();    }    return 0;    }
返回bytes单位的大小。





更多相关文章

  1. 使用intent调用Android系统自带应用
  2. android 加载动态库
  3. Android共享数据ContentProvider的使用
  4. android 学习之安装
  5. Android引入签名文件
  6. 启动emulator出错
  7. Android(安卓)Intent
  8. Android(安卓)Intent调用大全
  9. 【置顶】Errors occurred during the build完美解决之道

随机推荐

  1. 自定义对话框
  2. Android View系统解析(上)
  3. android gps经纬度实时更新,获取卫星数量
  4. android三种菜单介绍
  5. How to compile Android 1.6 (Android ec
  6. Android 可随意拖动的悬浮窗体
  7. Android(安卓)Tomcal SSL Https 单向篇
  8. android连续按两次返回退出程序(完整代码)
  9. ART崛起 Android 5.0将不再支持Dalvik
  10. KBinding 使用kotlin实现的Android MVVM