Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class Main {
    private static void copyFileFromAssets(Context context, String destPathName, String fileName) {

        File destFile = new File(destPathName);

        if (!destFile.exists()) {

            try {

                ///
                InputStream inputStream = context.getAssets().open(fileName);

                FileOutputStream outputStream = new FileOutputStream(destPathName);

                ///
                byte[] i_buffer = new byte[1024];

                for (;;) {

                    int length = inputStream.read(i_buffer);

                    if (length > 0) {

                        outputStream.write(i_buffer, 0, length);

                    } else {

                        break;
                    }
                }

                ///
                inputStream.close();

                outputStream.close();

            } catch (Exception e) {

                e.printStackTrace();
            }
        }
    }
}