安卓数据缓存的一些操作

来源:互联网 发布:大数据公司排名北京 编辑:程序博客网 时间:2024/06/15 20:58
    /*     * 从本地读取对象     */    public static Serializable readObject(String file) {        FileInputStream fis = null;        ObjectInputStream ois = null;        try {            fis = new FileInputStream(file);            ois = new ObjectInputStream(fis);            return (Serializable) ois.readObject();        } catch (FileNotFoundException e) {        } catch (Exception e) {            e.printStackTrace();        } finally {            try {                ois.close();            } catch (Exception e) {            }            try {                fis.close();            } catch (Exception e) {            }        }        return null;    }    /*     * 将数据保存在本地     */    public static boolean saveObject(Serializable ser, String file) {        FileOutputStream fos = null;        ObjectOutputStream oos = null;        try {            fos = new FileOutputStream(file);            oos = new ObjectOutputStream(fos);            oos.writeObject(ser);            oos.flush();            return true;        } catch (Exception e) {            e.printStackTrace();            return false;        } finally {            try {                oos.close();            } catch (Exception e) {            }            try {                fos.close();            } catch (Exception e) {            }        }    }

参考来源:http://www.tuicool.com/articles/AzUrMr7

0 0
原创粉丝点击