Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import java.io.FileOutputStream;
import java.util.Properties;

import android.util.Log;

public class Main {
    protected static final String TAG = "CommonUtil";
    private static String CONFIG_FILE_PATH = "/mnt/sdcard/config.properties";
    private static String ILLEGAL_STATE_ERROR = "ILLEGAL_STATE_EXCEPTION_ERROR";
    private static String ILLEGAL_ARGUMENT_ERROR = "ILLEGAL_ARGUMENT_ERROR";
    private static String INSTANTIATION_ERROR = "INSTANTIATION_ERROR";

    /**
     * Reset all error flags to 0.
     */
    public static void resetErrorFlags() {
        Log.i(TAG, "Reset all error flags.");

        Properties prop = new Properties();

        prop.put(ILLEGAL_STATE_ERROR, "0");
        prop.put(ILLEGAL_ARGUMENT_ERROR, "0");
        prop.put(INSTANTIATION_ERROR, "0");

        saveConfig(prop);
    }

    /**
     * Save config file.
     */
    private static void saveConfig(Properties properties) {
        try {
            File file = new File(CONFIG_FILE_PATH);
            if (!file.exists())
                file.createNewFile();
            FileOutputStream s = new FileOutputStream(file);
            properties.store(s, "");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}