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

public class Main {

    @SuppressWarnings("unused")
    private static boolean copy2SingleFileByChannel(File sourceFile, File destFile) {
        boolean copyOK = true;
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        FileChannel inputChannel = null;
        FileChannel outputChannel = null;
        try {
            inputStream = new FileInputStream(sourceFile);
            outputStream = new FileOutputStream(destFile);
            inputChannel = inputStream.getChannel();
            outputChannel = outputStream.getChannel();
            inputChannel.transferTo(0, inputChannel.size(), outputChannel);
        } catch (Exception e) {
            copyOK = false;
        } finally {
            try {
                inputChannel.close();
                inputStream.close();
                outputChannel.close();
                outputStream.close();
            } catch (IOException e) {
                copyOK = false;
                e.printStackTrace();
            }
        }
        return copyOK;
    }
}