我希望能将一个文本文件保存到插入在运行lollipop系统的HTC One M8手机中的SD卡上。然而,当我运行此代码时,它保存到内部存储器而不是SD卡。
String FILENAME = "mysavefile.txt";
File file = new File(Environment.getExternalStorageDirectory(), FILENAME);
if (isExternalStorageWritable()) {
errorSD.setVisibility(View.INVISIBLE);
try {
FileOutputStream fos = new FileOutputStream(file, false);
fos.write(allInformation.getBytes(), 0, 81);
fos.close();
successfulSubmissionToast();
} catch (FileNotFoundException e) {
e.printStackTrace();
errorSD.setVisibility(View.VISIBLE);
} catch (IOException e) {
e.printStackTrace();
}
它应该保存到
/storage/ext_sd
但实际上它保存到了。
/storage/emulated/0
然后我尝试手动输入我的SD卡位置,看看是否能够解决问题,但最终出现了FileNotFoundException异常。
File file = new File("/storage/ext_sd", FILENAME);
编辑: 我认为问题在于有多个外部存储设备,其中一个是永久的,另一个是临时的。问题是如何访问第二个。