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 java.io.File;

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

import java.io.IOException;

import android.graphics.Bitmap;

public class Main {
    public static void WriteToFile(String name, Bitmap bitmap, String path) throws IOException {
        String fString = name.replaceAll("/", ".");

        File dir = new File("/sdcard/OneBus/user/" + path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File f = new File("/sdcard/OneBus/user/" + path + "/" + fString + ".jpg");
        f.createNewFile();
        FileOutputStream fOut = null;
        try {
            fOut = new FileOutputStream(f);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        try {
            fOut.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            fOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}