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.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

import android.os.Environment;

public class Main {
    public static SQLiteDatabase mDB;

    /**
     * DB test
     */
    public static void runBackup(Context context) {
        File file = context.getDatabasePath("PhotoDeskHiddenFolder.db");
        int size = (int) file.length();

        String path = Environment.getExternalStorageDirectory() + "/PhotoDesk/";
        try {
            byte[] buffer = new byte[size];
            InputStream inputStream = new FileInputStream(file);
            inputStream.read(buffer);
            inputStream.close();

            File outputDBDirectory = new File(path);
            if (!outputDBDirectory.isDirectory())
                outputDBDirectory.mkdir();

            path += "test.db";

            File outputFile = new File(path);
            FileOutputStream outputStream = new FileOutputStream(outputFile);
            outputStream.write(buffer);
            outputStream.flush();
            outputStream.close();

        } catch (Exception e) {
        }
    }

    /**
     * DB close.
     */
    public void close() {
        mDB.close();
    }
}