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.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.os.Environment;

public class Main {
    /**
     * Dump the database file to external storage
     *
     * @param packageName
     * @param fileName
     * @throws IOException
     */
    public static void dumpDatabase(String packageName, String fileName) throws IOException {
        File dbFile = new File("/data/data/" + packageName + "/databases/" + fileName);
        if (dbFile.exists()) {
            FileInputStream fis = new FileInputStream(dbFile);
            String outFileName = Environment.getExternalStorageDirectory() + "/" + fileName;
            OutputStream output = new FileOutputStream(outFileName);
            byte[] buffer = new byte[1024];
            int length;
            while ((length = fis.read(buffer)) > 0) {
                output.write(buffer, 0, length);
            }
            output.flush();
            output.close();
            fis.close();
        }
    }
}