Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import android.content.Context;
import android.content.res.AssetManager;

public class Main {
    public static void copyAsset(Context context, String assetFileName, String dstFile) {
        AssetManager assetManager = null;
        assetManager = context.getAssets();
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            inputStream = assetManager.open(assetFileName);
            fileOutputStream = new FileOutputStream(dstFile);
            byte[] buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
            fileOutputStream.write(buffer);
            fileOutputStream.flush();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                inputStream.close();
                fileOutputStream.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}