如何查看SD卡文件系统的类型?

Ang*_*i H 1 android android-sdcard

如何检查SD卡文件系统的类型?

例如,在Windows中我们可以看到NTFS,FAT32,exFAT等.

提前致谢.

sam*_*gak 5

一种解决方案是运行mount命令,然后对结果执行一些字符串处理:

    try{
        Process mount = Runtime.getRuntime().exec("mount");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mount.getInputStream()));
        mount.waitFor();

        String extPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        String line;
        while ((line = bufferedReader.readLine()) != null)
        {
            String[] split = line.split("\\s+");
            for(int i = 0; i < split.length - 1; i++)
            {
                if(split[i].contentEquals(extPath) ||
                    split[i].contains("sdcard") ||
                    split[i].contains("_sd") ||
                    split[i].contains("extSd") ||
                    split[i].contains("_SD"))   // Add wildcards to match against here
                {
                    String strMount = split[i];
                    String strFileSystem = split[i+1];

                    // Add to a list/array of mount points and file systems here...
                    Log.i("SDCard", "mount point: "+ strMount + " file system: " + strFileSystem);
                }
            }
        }           
    }catch(IOException e){
        e.printStackTrace();            
    }catch(InterruptedException e){
        e.printStackTrace();            
    }
Run Code Online (Sandbox Code Playgroud)

在我的G Pro上运行这个给了我以下结果:

mount point: /mnt/media_rw/external_SD file system: vfat
mount point: /storage/external_SD file system: fuse
Run Code Online (Sandbox Code Playgroud)

一些常见的Android文件系统类型: