安卓通过openFileInput/openFileOutput读取或保留任意对象
来源:互联网 发布:js e.currenttarget 编辑:程序博客网 时间:2024/06/07 19:29
安卓提供的openFileInput/openFileOutput读取或保留任意对象
public class ObjectSave { private static UserInfo info; /** * 读取文件存储数据 * * @return 返回数据对象 */ public static Object getObject(String name) { FileInputStream fi = null; ObjectInputStream oi = null; try { fi = BaseApplication.context.openFileInput(name); oi = new ObjectInputStream(fi); return oi.readObject(); } catch (Exception e) { e.printStackTrace(); } finally { if (fi != null) { try { fi.close(); } catch (IOException e) { e.printStackTrace(); } } if (oi != null) { try { oi.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } /** * 将指定文件存储到系统文件夹中 * * @param name 文件名 * @param object 文件对象 */ public static void SaveObject(String name, Object object) { FileOutputStream fo = null; ObjectOutputStream oo = null; try { fo = BaseApplication.context.openFileOutput(name, Context.MODE_PRIVATE); oo = new ObjectOutputStream(fo); oo.writeObject(object); } catch (Exception e) { e.printStackTrace(); } finally { if (fo != null) { try { fo.close(); } catch (IOException e) { e.printStackTrace(); } } if (oo != null) { try { oo.close(); } catch (IOException e) { e.printStackTrace(); } } } } /** * 得到UserInfo类的对象 */ public static UserInfo getUserInfo() { if (info == null) { info = (UserInfo) getObject("userinfo.dat"); if (info == null) { info = new UserInfo(); } } return info; } /** * 存储UserInfo类的对象 */ public static void SaveUserInfo(UserInfo userInfo) { if (info == null) { info = (UserInfo) getObject("userinfo.dat"); if (info == null) { info = new UserInfo(); } } info = userInfo; SaveObject("userinfo.dat", info); }
图中画圈的可以是任意你想保留的对象
阅读全文
0 0
- 安卓通过openFileInput/openFileOutput读取或保留任意对象
- 使用openFileOutput和openFileInput读取文件
- andriod 内存数据读取 写入操作(openFileInput,openFileOutput)
- openFileOutput/openFileInput使用详解
- Android openFileOutput 和 openFileInput
- Android openFileOutput 和 openFileInput
- openFileOutput和openFileInput
- openFileOutput()和openFileInput
- 文件存储openFileOutput和openFileInput
- 文件存储openFileOutput和openFileInput
- Android之openFileoutput和openFileinput
- 操作手机内存:openFileOutput、openFileInput
- 文件存储openFileOutput和openFileInput
- 本地存储(openFileInput,openFileOutput)
- android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
- android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
- android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()
- android应用私有存储文件的写入与读取-openFileInput 和 openFileOutput
- POI文件excel文件导入导出
- 二维地图引擎
- spring-boot集成定时任务
- 图论基础SPFA:poj3268模板题
- C#网络编程系列文章(二)之Socket实现同步TCP服务器
- 安卓通过openFileInput/openFileOutput读取或保留任意对象
- 乐刻大数据平台架构实践
- iOS 打包上传 appStore 错误集
- Java ExecutorService四种线程池的例子与说明
- 负载均衡重点业务梳理
- centos 安装 netstat ifconfig
- python去除list中空字符串最快最简单的方法
- Android Studio配置文件路径修改
- PAT (Advanced Level) Practise 1005. Spell It Right (20)