Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.graphics.Bitmap;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import static android.content.Context.MODE_PRIVATE;

public class Main {

    public static void saveBitmapToCacheDir(Context context, Bitmap bitmap, String name) {
        try {
            File file = new File(context.getCacheDir(), name);
            if (file.exists()) {
                file.delete();
            }
            FileOutputStream fos = context.openFileOutput(name, MODE_PRIVATE);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}