public class UDiskUtil {
public final static String searchPath() {
String filePath = "/proc/mounts";
File file = new File(filePath);
List<String> lineList = new ArrayList<>();
InputStream inputStream =null;
try {
inputStream = new FileInputStream(file);
if (inputStream != null) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GBK");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = "";
while ((line = bufferedReader.readLine()) != null) {
// Log.e("TAG",line);
if (line.contains("vfat")) {
lineList.add(line);
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String editPath = lineList.get(lineList.size() - 1);
int start = editPath.indexOf("/mnt");
int end = editPath.indexOf(" vfat");
String path = editPath.substring(start, end);
Log.d("TAG_SelectBusLineDialog", "path: " + path);
return path;
}
}
android 获取u盘路径
最新推荐文章于 2025-03-23 13:56:09 发布
该代码段展示了一个Java方法,用于查找系统中挂载的vfat文件系统的路径。首先,它打开并读取'/proc/mounts'文件,然后使用BufferedReader逐行读取,当找到包含'vfat'的行时,将其添加到列表中。最后,从列表中获取最后一个包含vfat的路径,并截取从'/mnt'开始到'vfat'结束的子字符串作为返回路径。
2891

被折叠的 条评论
为什么被折叠?



