2016-02-26 51 views
0

我正在写一个应用程序,将文件写入USB闪存驱动器(通过USB OTG),然后将其从手机中删除并用于其他地方(仅支持FAT32)。我需要能够确定外部存储是否格式正确,如果没有,我需要告诉用户。如何确定Android中外部存储的文件系统类型?

如果我连接FAT32格式化的驱动器,调用安装在Android的壳仅表示“导火索”作为文件系统:

/dev/fuse /storage/usbotg fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0 

有没有一种方法来确定文件系统,通过命令行或编程?

回答

1

你mount命令的列表:

ArrayList<String> listMount = new ArrayList<String>(); 
Process p=null; 

    try { 
     p = Runtime.getRuntime().exec("mount"); 
     BufferedReader in2 = new BufferedReader(new InputStreamReader(p.getInputStream())); 
     String line; 
     while ((line = in2.readLine()) != null) { 
      listMount.add(line); 
     } 
    } catch (Exception e) { 
     // manage exception 
    } 

在listMount有坐骑的输出。搜索你的/ dev,并检查这是vfat(文件系统FAT或FAT32)。如果只看到“保险丝”,我相信android只能识别你的设备USB OTG而不是最终的USB。

fuse用于挂载其他文件系统类型,如NTFS。

相关问题