【问题标题】:How can I determine the files system type of external storage in Android?如何确定 Android 中外部存储的文件系统类型?
【发布时间】:2016-06-09 18:41:52
【问题描述】:

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

如果我连接的是 FAT32 格式的驱动器,在 android shell 上调用 mount 只会将“fuse”作为文件系统:

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

有没有办法通过命令行或编程方式确定文件系统?

【问题讨论】:

    标签: android usb mount


    【解决方案1】:

    你会得到挂载命令列表:

    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 中有 mount 的输出。搜索您的 /dev 并检查它是否为 vfat(文件系统 FAT 或 FAT32)。如果只看到“保险丝”,我相信 android 只能识别您的设备 USB OTG 而不是最终的 USB。

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

    【讨论】:

      猜你喜欢
      • 2022-08-10
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多