Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.text.TextUtils;

import java.io.File;

import java.io.FileOutputStream;

import java.io.ObjectOutputStream;

import java.util.zip.GZIPOutputStream;

public class Main {

    public static boolean saveObjectToFile(String filePath, Object object) {
        if (!TextUtils.isEmpty(filePath)) {
            File cacheFile = null;

            try {
                cacheFile = new File(filePath);
                if (cacheFile.exists()) {
                    cacheFile.delete();
                }

                if (!cacheFile.getParentFile().exists()) {
                    cacheFile.getParentFile().mkdirs();
                }

                cacheFile.createNewFile();
            } catch (Throwable var6) {
                var6.printStackTrace();
                cacheFile = null;
            }

            if (cacheFile != null) {
                try {
                    FileOutputStream t = new FileOutputStream(cacheFile);
                    GZIPOutputStream gzos = new GZIPOutputStream(t);
                    ObjectOutputStream oos = new ObjectOutputStream(gzos);
                    oos.writeObject(object);
                    oos.flush();
                    oos.close();
                    return true;
                } catch (Throwable var7) {
                    var7.printStackTrace();
                }
            }
        }

        return false;
    }
}