Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

public class Main {

    public static boolean saveFile(Bitmap bm, String fileDir, String fileName) {
        try {
            File dirFile = new File(fileDir);
            if (!dirFile.exists()) {
                dirFile.mkdirs();
            }
            File myCaptureFile = new File(fileDir, fileName + ".jpg");
            if (myCaptureFile.exists()) {
                myCaptureFile = new File(fileDir, fileName + System.currentTimeMillis() + ".jpg");
            }
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
            bm.compress(CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}