我想寫一個.csv文件到我已連接到我的android digiland平板電腦的micro SD卡上。每當我嘗試向SD卡寫入文件時,將SD卡插入計算機時唯一顯示的文件是名爲lost.dir的空文件夾。我對此做了一些研究,聽起來像lost.dir是一些數據丟失時創建的文件夾。我不確定數據爲什麼會丟失。我一定要正確地安裝和卸載SD卡,並且我不知道如何解決此問題。這裏是我使用的代碼:在Android上寫文件到SD卡(lost.dir)
String string =
" \n" + teamNum + "," + matchNum + ","+ gearPoints + "," + climbScored
+ "," + ballsHigh + "," + ballsLow + "," + gearsAuto + "," +
hiBallsAuto + "," + lowBallsAuto + "," + driveForward + "";
if(isSdWriteable()) {
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "scout9000.csv");
try {
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
System.out.println("Error writing file.");
}
}
這裏是我的isSdWriteable功能:
public boolean isSdWriteable() {
String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
任何幫助表示讚賞。
IIRC lost.dir創建每次使用Android插任何儲存時間 – Qwertie