Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
String filename = dateFormat.format( now );
File accelerometerDataFile = new File(getExternalCacheDir(), filename+".csv");
PrintWriter printWriter =
new PrintWriter(new BufferedWriter(new FileWriter(dataFile)));
printWriter.println(CSV_HEADER);
if (printWriter != null)
{
StringBuffer sb = new StringBuffer()
.append(z).append(CSV_DELIM)
.append((eventTime / 1000000) - startTime);
printWriter.println(sb.toString());
if (printWriter.checkError())
{
Log.w(TAG, "Error writing sensor event data");
}
}
if (printWriter != null)
{
printWriter.close();
}