create App Private File via Context - Android App

Android examples for App:Resource

Description

create App Private File via Context

Demo Code


//package com.java2s;

import java.io.OutputStream;
import android.content.Context;
import android.util.Log;

public class Main {
    private static final String LOG_TAG = "AndroidFileUtils";

    /**/*from  w  ww  .  j  a  v  a  2 s. c  o  m*/
     * @param pContext
     * @param pFileName
     * @param pFileData
     * @return
     */
    public static boolean createAppPrivateFile(Context pContext,
            String pFileName, byte[] pFileData) {
        try {
            OutputStream os = pContext.openFileOutput(pFileName,
                    Context.MODE_PRIVATE);
            os.write(pFileData);
            os.close();
            return true;
        } catch (Exception e) {
            Log.e(LOG_TAG, "createAppPrivateFile: " + pFileName, e);
            return false;
        }
    }
}

Related Tutorials