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.content.Context;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Main {
    public static void writeBitmapToDisk(String url, Bitmap bmp, Context ctx, CompressFormat format) {
        FileOutputStream fos;
        String fileName = constructFileName(url);
        try {
            if (bmp != null) {
                fos = new FileOutputStream(new File(ctx.getCacheDir(), fileName));
                bmp.compress(format, 75, fos);
                fos.close();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String constructFileName(String url) {
        return url.replaceAll("/", "_");
    }
}