Copy Database with FileChannel - Android Database

Android examples for Database:Database Backup

Description

Copy Database with FileChannel

Demo Code


//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class Main {
    private static boolean CopyDatabase(File source, File dest) {
        try {// w w w .  j a  va2  s .  co m
            FileChannel sourceChannel = new FileInputStream(source)
                    .getChannel();
            FileChannel destChannel = new FileOutputStream(dest)
                    .getChannel();
            destChannel
                    .transferFrom(sourceChannel, 0, sourceChannel.size());
            sourceChannel.close();
            destChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

Related Tutorials