Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.content.Context;

import android.util.Log;

public class Main {
    public static void writeInteractionInFile(Context context, String startTime, String endTime, long duration,
            String filename) throws IOException, Exception {

        BufferedWriter writer = null;
        //String path="sdcard/LifeTracker/lifetracker.csv";
        File dir = new File("sdcard/SleepLog");
        boolean flag = dir.mkdir();
        //Log.d("Directory created?",""+flag);
        File file = new File(dir.getAbsolutePath(), filename);
        if (file.exists() == false) {
            //                  Intent service = new Intent(context,DataBaseService.class);
            //                  context.startService(service);
            file.createNewFile();
            writer = new BufferedWriter(new FileWriter(file, true));
            writer.write("Start Time,End Time,Duration");
            writer.newLine();
            writer.write(startTime + "," + endTime + "," + duration);
        } else {
            writer = new BufferedWriter(new FileWriter(file, true));
            writer.newLine();
            writer.write(startTime + "," + endTime + "," + duration);
        }
        Log.d("Appended", "True");
        writer.flush();
        writer.close();

    }
}