您的位置:首页 > 移动开发 > Android开发

android获取扩展存储路径,TF卡、U盘等

2014-06-24 15:53 531 查看
/**
* 获取扩展存储路径,TF卡、U盘
*/
public static String getExternalStorageDirectory(){
String dir = new String();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure")) continue;
if (line.contains("asec")) continue;

if (line.contains("fat")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
dir = dir.concat(columns[1] + "\n");
}
} else if (line.contains("fuse")) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
dir = dir.concat(columns[1] + "\n");
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dir;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: