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.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

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

public class Main {
    public final static String TAG = "HubDbHelper";
    private static final boolean Debug = true;
    private final static String BASE_DIR = "Hub";

    /**
     * Return the absolute path to the hub database.
     *
     * @return path The path to the db as a string
     */
    private static String getDbPath() {
        if (Debug)
            Log.i(TAG, "getDBPath() called.");

        String path = Environment.getExternalStorageDirectory().getPath() + "/" + BASE_DIR;

        File dbDir = new File(path);
        if (!dbDir.isDirectory()) {
            try {
                if (Debug)
                    Log.i(TAG, "Trying to create " + path);
                dbDir.mkdirs();
            } catch (Exception e) {
                final Writer result = new StringWriter();
                final PrintWriter printWriter = new PrintWriter(result);
                e.printStackTrace(printWriter);
                Log.e(TAG, result.toString());
            }
        }
        return path;
    }
}