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.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.ProgressDialog;
import android.content.Context;

public class Main {

    public static File copy1(Context context, String filename, String destfilename, ProgressDialog pd) {

        try {
            InputStream in = context.getAssets().open(filename);
            int max = in.available();
            if (pd != null) {
                pd.setMax(max);
            }

            File file = new File(destfilename);
            OutputStream out = new FileOutputStream(file);
            byte[] byt = new byte[1024];
            int len = 0;
            int total = 0;
            while ((len = in.read(byt)) != -1) {
                out.write(byt, 0, len);
                total += len;
                if (pd != null) {
                    pd.setProgress(total);
                }
            }
            out.flush();
            out.close();
            in.close();

            return file;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}