Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.text.TextUtils;

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

import java.io.FileOutputStream;

public class Main {

    public static boolean copyFile(String fromFilePath, String toFilePath) {
        if (!TextUtils.isEmpty(fromFilePath) && !TextUtils.isEmpty(toFilePath)) {
            if (!(new File(fromFilePath)).exists()) {
                return false;
            } else {
                try {
                    FileInputStream e = new FileInputStream(fromFilePath);
                    FileOutputStream fosto = new FileOutputStream(toFilePath);
                    copyFile(e, fosto);
                    return true;
                } catch (Throwable var4) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }

    public static void copyFile(FileInputStream src, FileOutputStream dst) throws Throwable {
        byte[] buf = new byte[65536];

        for (int len = src.read(buf); len > 0; len = src.read(buf)) {
            dst.write(buf, 0, len);
        }

        src.close();
        dst.close();
    }
}