我想做一个Android活动写测试文件到设备的可移动SD卡。然后我需要能够验证它被写入。我已经能够写入手机的内部存储器(称为外部存储器,虽然不是),但不能写入可移动的SD卡。我想我需要得到正确的路径。安卓 - 保存文件到可移动标清和读取
我已经能够检查与此代码的可移动SD卡的存在,但一直没能将其转化为写入文件:
String secStore = System.getenv("SECONDARY_STORAGE");
File path = new File(secStore);
StatFs stat = new StatFs(path.getPath());
这是我写测试文件代码BT就像我说的,把它写入到设备的内部存储:
File dir = new File(android.os.Environment.getExternalStorageDirectory(), "TestFolder");
if (!dir.exists()) {
dir.mkdirs();
}
String filename = "SD_Test.txt";
try {
File f = new File(dir + File.separator + filename);
FileOutputStream fOut = new FileOutputStream(f);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("Testing SD Card");
myOutWriter.flush();
myOutWriter.close();
fOut.close();
if(f.exists()){
Toast.makeText(getBaseContext(),
"File Created",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
请帮帮忙,我一直在这几天,我坚持!