Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    private static final int bufferSize = 4096;

    private static int copyFile(final File src, final File dst) throws IOException {
        int totalBytes = 0;
        final InputStream in = new BufferedInputStream(new FileInputStream(src));
        try {
            final OutputStream out = new BufferedOutputStream(new FileOutputStream(dst));
            try {
                final byte[] buf = new byte[bufferSize];
                while (true) {
                    int count;
                    if ((count = in.read(buf)) == -1) {
                        break;
                    }
                    out.write(buf, 0, count);
                    totalBytes += count;
                }
            } finally {
                out.close();
            }
        } finally {
            in.close();
        }
        return totalBytes;
    }
}