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 {
    public static void copyFile(File src, File dest) throws IOException {
        FileOutputStream fileOut = null;
        FileInputStream fileIn = null;
        try {
            fileOut = new FileOutputStream(dest);
            fileIn = new FileInputStream(src);
            FileChannel inChannel = fileIn.getChannel();
            FileChannel outChannel = fileOut.getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (fileIn != null) {
                fileIn.close();
            }
            if (fileOut != null) {
                fileOut.close();
            }
        }
    }
}