Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: GNU General Public License 

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

import android.content.Context;

import android.util.Log;

public class Main {
    public static String createExternalStoragePrivateFile(Context appCtx, InputStream is, String fileName) {

        File file = new File(appCtx.getExternalFilesDir(null), fileName);

        try {
            //InputStream is = appCtx.getResources().openRawResource(R.raw.calipso);
            OutputStream os = new FileOutputStream(file);
            byte[] data = new byte[is.available()];
            is.read(data);
            os.write(data);
            is.close();
            os.close();
        } catch (IOException e) {
            // Unable to create file, likely because external storage is
            // not currently mounted.
            Log.w("ExternalStorage", "Error writing " + file, e);
        }

        return file.getPath();
    }
}