Java tutorial
//package com.java2s; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Date; import android.os.Environment; import android.util.Log; public class Main { public static void writeLifeLogCountInFile(int walking, int running, int vehicle, int bicycle, String filename) throws IOException { Date date = new Date(); BufferedWriter writer = null; File dir = new File(Environment.getExternalStorageDirectory() + "/LifeLog"); Log.d("Directory PATH", dir.getAbsolutePath()); boolean flag = dir.mkdir(); Log.d("Directory created?", "" + flag); File file = new File(dir.getAbsolutePath(), filename); if (file.exists() == false) { file.createNewFile(); writer = new BufferedWriter(new FileWriter(file, true)); writer.write("Date,Walking,Running,Bicycle,Vehicle"); writer.newLine(); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); } else { writer = new BufferedWriter(new FileWriter(file, true)); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); Log.d("Appended", "True"); } writer.flush(); writer.close(); } }