save Res - Android App

Android examples for App:Resource

Description

save Res

Demo Code


//package com.java2s;

import java.io.FileOutputStream;

import java.io.InputStream;

import android.content.Context;

import android.util.Log;

public class Main {
    public static boolean saveRes(Context gContext, int res, String dirjpg) {
        InputStream is = gContext.getApplicationContext().getResources()
                .openRawResource(res);/*  w w w.  ja v  a  2  s.com*/
        boolean rez = false;
        try {
            FileOutputStream rtFOS = new FileOutputStream(dirjpg + "/"
                    + res + ".gif");
            byte[] buffer = new byte[4096];
            int n = -1;
            while ((n = is.read(buffer, 0, 4095)) != -1) {
                if (n > 0)
                    rtFOS.write(buffer, 0, n);
                rez = true;
            }
            rtFOS.flush();
            rtFOS.close();
        } catch (Exception e) {
            Log.e("FullscreenActivity", e.toString());
        }
        return rez;
    }
}

Related Tutorials