在Android中,要实现对可读/可写可移除SD卡的访问,可以使用以下解决方法:
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// SD卡可用
// 进行读写操作
} else {
// SD卡不可用
}
File sdCard = Environment.getExternalStorageDirectory();
String sdCardPath = sdCard.getAbsolutePath();
// 创建文件对象
File file = new File(sdCardPath + "/test.txt");
try {
// 写入文件
FileWriter writer = new FileWriter(file);
writer.append("Hello, SD Card!");
writer.flush();
writer.close();
// 读取文件
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
reader.close();
// 输出文件内容
System.out.println(line);
} catch (IOException e) {
e.printStackTrace();
}
请注意,上述代码仅为示例,实际使用时请根据自己的需求进行适当的修改和错误处理。