Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.os.Environment;
import android.util.Log;

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void appendLog(String text) {
        Log.d("LOGFILE", text);
        SimpleDateFormat sTime = new SimpleDateFormat("dd/MMM/yyyy - hh:mm:ss");
        String timeFormat = sTime.format(new Date());

        File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File(sdCard.getAbsolutePath() + "/Cura/Logs/");
        dir.mkdirs();
        File logFile = new File(dir, "Cura_Logs_DEBUG.txt");
        if (!logFile.exists()) {
            try {
                logFile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
            if (text.compareTo("wipe") == 0)
                logFile.delete();
            else {
                buf.append("[" + timeFormat + "] - ");
                buf.append(text);
                buf.newLine();
                buf.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}