I am trying to write a .csv file to a micro SD card I have connected to my android Digiland tablet. Whenever I try to write a file to the SD card, the only thing that shows up on the SD card when I plug it into my computer is an empty folder named lost.dir. I have done some research on this and it sounds like lost.dir is a folder created when some data is lost. I am not sure why the data is being lost. I make sure to properly mount and unmount the SD card, and I am at a loss as to what to do to fix this problem. Here is the code I am using:
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.");
}
}
Here is my isSdWriteable function:
public boolean isSdWriteable() {
String state = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
Any help is appreciated.