Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import android.content.Context;

public class Main {

    public static boolean cache(Context context, String file, String data, int mode) {
        return cache(context, file, data.getBytes(), mode);
    }

    public static boolean cache(Context context, String file, byte[] data, int mode) {
        boolean bResult = false;
        if (null != data && data.length > 0) {
            FileOutputStream fos = null;
            try {
                fos = context.openFileOutput(file, mode);
                fos.write(data);
                fos.flush();
                bResult = true;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (null != fos) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return bResult;
    }
}