Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Main {
    /**
     * Copy file a to b and remove a. 
     * @param source source file
     * @param destination destination file
     * @return true if success, false if fail.
     */
    public static boolean move(File source, File destination) {
        try {
            FileInputStream in = new FileInputStream(source);
            FileOutputStream out = new FileOutputStream(destination);
            byte[] buffer = new byte[1024 * 1024];
            int size;
            while ((size = in.read(buffer)) >= 0) {
                out.write(buffer, 0, size);
            }
            in.close();
            out.flush();
            out.close();
            source.delete();
            return true;
        } catch (Exception exp) {
            exp.printStackTrace();
        }
        return false;
    }
}