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.IOException;
import java.nio.channels.FileChannel;

import android.util.Log;

public class Main {
    private static void copy(File srcFile, File targetFile) throws IOException {
        FileChannel src = null, dst = null;
        try {
            if (srcFile.exists() && (!targetFile.exists() || targetFile.delete())) {
                src = new FileInputStream(srcFile).getChannel();
                dst = new FileOutputStream(targetFile).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        } finally {
            try {
                if (src != null)
                    src.close();
            } catch (IOException e) {
                Log.e("DIARY", "Failed to close resource.", e);
            }
            try {
                if (dst != null)
                    src.close();
            } catch (IOException e) {
                Log.e("DIARY", "Failed to close resource.", e);
            }
        }
    }
}