Android 如何检查SD卡的类型';s文件系统?
如何检查SD卡文件系统的类型 例如,在Windows中,我们可以看到NTFS、FAT32、exFAT等Android 如何检查SD卡的类型';s文件系统?,android,android-sdcard,Android,Android Sdcard,如何检查SD卡文件系统的类型 例如,在Windows中,我们可以看到NTFS、FAT32、exFAT等 提前感谢。一种解决方案是运行mount命令,然后对结果执行一些字符串处理: try{ Process mount = Runtime.getRuntime().exec("mount"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mount.getI
提前感谢。一种解决方案是运行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();
}
一些常见的Android文件系统类型:
- yaffs/yaffs2-
- ext4-
- 保险丝-
- tmpfs-
- vfat-
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();
}
一些常见的Android文件系统类型:
- yaffs/yaffs2-
- ext4-
- 保险丝-
- tmpfs-
- vfat-
public static String getFileSystem(File path){
try{
Process mount = Runtime.getRuntime().exec("mount");
BufferedReader reader = new BufferedReader(new InputStreamReader(mount.getInputStream()));
mount.waitFor();
String line;
while ((line = reader.readLine()) != null) {
String[] split = line.split("\\s+");
for (int i = 0; i < split.length - 1; i++){
if (!split[i].equals("/") && path.getAbsolutePath().startsWith(split[i]))
return split[i + 1];
}
}
reader.close();
mount.destroy();
}catch(IOException | InterruptedException e){
e.printStackTrace();
}
return null;
}
将产生以下输出:
I/---: Filesystem = vfat
对于自定义路径,我们可以使用以下静态方法:
public static String getFileSystem(File path){
try{
Process mount = Runtime.getRuntime().exec("mount");
BufferedReader reader = new BufferedReader(new InputStreamReader(mount.getInputStream()));
mount.waitFor();
String line;
while ((line = reader.readLine()) != null) {
String[] split = line.split("\\s+");
for (int i = 0; i < split.length - 1; i++){
if (!split[i].equals("/") && path.getAbsolutePath().startsWith(split[i]))
return split[i + 1];
}
}
reader.close();
mount.destroy();
}catch(IOException | InterruptedException e){
e.printStackTrace();
}
return null;
}
将产生以下输出:
I/---: Filesystem = vfat
谢谢你之前的回答,当我得到帮助时,我会接受的。我有以下结果:“挂载点:/mnt/sdcard/.android\u安全文件系统:tmpfs”。但根据您的结果:“装载点:/mnt/media\u rw/external\u SD文件系统:vfat”和“装载点:/storage/external\u SD文件系统:fuse”。那么,这意味着什么?什么是tmpfs、vfat和fuse?我已经为我的许多朋友的手机(JellyBean)测试了你的代码。它只适用于手机内存(1.4GB),而不适用于SD卡。如果你能再次帮助我,我会支持你的评论或支持你的回答。谢谢…我已经编辑了答案以包含更多的字符串来匹配。SD卡路径对于不同的手机制造商是不同的。此问题包含更多信息:您还可以与从Environment.getExternalStorageDirectory()返回的结果进行匹配。此外,请检查您朋友手机上的路径,并将其添加到列表中。再次感谢,这非常有帮助。:)@UbuntuForums_Staff_是巨魔爪哇谢谢你之前的回答,当我得到帮助时我会接受的。我有以下结果:“挂载点:/mnt/sdcard/.android\u安全文件系统:tmpfs”。但根据您的结果:“装载点:/mnt/media\u rw/external\u SD文件系统:vfat”和“装载点:/storage/external\u SD文件系统:fuse”。那么,这意味着什么?什么是tmpfs、vfat和fuse?我已经为我的许多朋友的手机(JellyBean)测试了你的代码。它只适用于手机内存(1.4GB),而不适用于SD卡。如果你能再次帮助我,我会支持你的评论或支持你的回答。谢谢…我已经编辑了答案以包含更多的字符串来匹配。SD卡路径对于不同的手机制造商是不同的。此问题包含更多信息:您还可以与从Environment.getExternalStorageDirectory()返回的结果进行匹配。此外,请检查您朋友手机上的路径,并将其添加到列表中。再次感谢,这非常有帮助。:)@工作人员是爪哇巨魔