Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import android.content.*;

import android.util.Log;

public class Main {
    public static void logProgressReport(Context c, String[] logs) {
        String dir = c.getExternalFilesDir(null).getParent();
        try {
            File file = new File(dir + "/sf_reports.log");
            boolean append = false;
            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            } else {
                /*
                if(file.length() >= 2097152){
                   // set log file max size to 2mb
                   append = false;
                }
                 */

            }
            FileOutputStream fos = new FileOutputStream(file, append);

            for (String log : logs) {
                fos.write((log + "\n\n").getBytes());
            }
            fos.close();
        } catch (IOException ioe) {
            Log.e("AndroidUtils", "An exception has occured in logProgressReport!");
            ioe.printStackTrace();
        }
    }
}