Android获取机身存储、内置SD卡与外置TF卡路径
来源:互联网 发布:js获取被选中的radio 编辑:程序博客网 时间:2024/05/17 02:30
获取机身存储路径(可以通过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单位的大小。
0 0
- Android获取机身存储、内置SD卡与外置TF卡路径
- 获取SD卡 tf卡 内置外置存储卡路径名称 路径的方式
- Android本地文件存储,机身和外置sd卡
- android获取内置和外置SD卡路径
- android获取内置和外置SD卡路径
- android获取内置和外置SD卡路径
- android获取内置和外置SD卡路径
- android获取内置和外置SD卡路径
- Android获取内置和外置sd卡路径的方法
- Android 内部存储(外置SD卡)和扩展存储卡(TF卡)路径的获取
- Android获取外置存储卡、内置存储卡路径
- 获取android 内置与外置SD卡路径及可用空间
- Android判断获取内置外置sd卡
- Android 通过反射调用获取内置存储和外置sd卡根路径(适用于各个版本)
- 获取Android系统所有内置SD卡以及外置SD卡路径
- android 获取文件路径(内置sd卡和外置sd卡)。
- Android中获取内置SD卡和外置SD卡路径的方法
- Android 4.0获取外置SD卡 路径
- 深入理解Linux磁盘的奥秘
- 使用pull解析、生成XML文档
- JavaBean规范
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- UESTC 8 God Only Knows!
- Android获取机身存储、内置SD卡与外置TF卡路径
- Dubbo和Spring集成Demo
- “微服务” 的架构终将成为产品架构上的主流
- 闲聊DTD语法
- play验证码模块的实现
- Reverse Integer
- HDU 3974 Assign the task [并查集扩展]
- sqoop数据导出导入命令
- Ecmascript 标准中的Array.prototype中的函数定义