嘗試這種方式來寫txt文件到SD卡,從SD卡讀取文件非常相似,
File getExternalDir(String dirName) throws IOException {
File dir = new File(Environment.getExternalStorageDirectory(), dirName);
if (!dir.exists()) {
dir.mkdirs();
}
return dir;
}
void saveFile(){
File txtFile = new File(getExternalDir(cacheDirectory), fileName);
// write the txt file to SD card
FileOutputStream outputStream = new FileOutputStream(txtFile, true);
OutputStreamWriter writer = new OutputStreamWriter(outputStream);
writer.write(result.toString());
writer.flush();
writer.close();
}
http://stackoverflow.com/questions/8019783/reading-and-寫一個文件,從-SD卡 –