Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

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

public class Main {
    public static String extractFromAssets(Context ctx, String file, String destinationDirectory)
            throws IOException, FileNotFoundException {
        final int BUFFER = 2048;
        BufferedOutputStream dest = null;
        AssetManager assetManager = ctx.getAssets();
        InputStream in = assetManager.open(file);
        String destinationFilename = destinationDirectory + File.separator + file;
        OutputStream out = new FileOutputStream(destinationFilename);
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        in.close();
        out.close();
        return destinationFilename;
    }
}