Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    private static final String TAG = "Helper";

    /**
     * Copies a file from res/raw to destination (typically context.getFilesDir())
     */
    public static void copyInputFileStreamToFilesystem(InputStream in, String outputFilePathName)
            throws IOException {
        Log.i(TAG, "copyInputFileStreamToFilesystem() outputFilePathName: " + outputFilePathName);
        OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFilePathName));
        byte[] buffer = new byte[4096];
        int len = in.read(buffer);
        while (len != -1) {
            out.write(buffer, 0, len);
            len = in.read(buffer);
        }
        out.close();
    }
}