List集合存储到本地
来源:互联网 发布:淘宝主图视频大小限制 编辑:程序博客网 时间:2024/06/05 02:03
首先泛型要先实现Serializable接口
然后就可以使用如下工具类了
package com.tools.dbattery.bean;import java.io.Serializable;/** * Name: ChargeRecordsInfo * Author: liuan * creatTime:2017-08-02 18:09 * Email:1377093782@qq.com */public class ChargeRecordsInfo implements Serializable { public String beaginTime; public String beaginLevel; public String endLevel; public String charegTime; public int boostTime; public int coolerTime; public void setBeaginTime(String beaginTime) { this.beaginTime = beaginTime; } public void setBeaginLevel(String beaginLevel) { this.beaginLevel = beaginLevel; } public void setEndLevel(String endLevel) { this.endLevel = endLevel; } public void setCharegTime(String charegTime) { this.charegTime = charegTime; } public void setBoostTime(int boostTime) { this.boostTime = boostTime; } public void setCoolerTime(int coolerTime) { this.coolerTime = coolerTime; } @Override public String toString() { return "ChargeRecordsInfo{" + "beaginTime='" + beaginTime + '\'' + ", beaginLevel='" + beaginLevel + '\'' + ", endLevel='" + endLevel + '\'' + ", charegTime='" + charegTime + '\'' + ", boostTime=" + boostTime + ", coolerTime=" + coolerTime + '}'; }}
/** * Name: ListSaveUtils * Author: liuan * creatTime:2017-08-03 15:30 * Email:1377093782@qq.com */public class ListSaveUtils { /** * 数据存放在本地 * * @param tArrayList */ public static void saveStorage2SDCard(List tArrayList, String fileName) { FileOutputStream fileOutputStream = null; ObjectOutputStream objectOutputStream = null; FileInputStream fileInputStream = null; try { File file = new File(AppContext.getFilesDir().getAbsoluteFile(), fileName); fileOutputStream = new FileOutputStream(file.toString()); //新建一个内容为空的文件 objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(tArrayList); } catch (Exception e) { e.printStackTrace(); } if (objectOutputStream != null) { try { objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } /** * 获取本地的List数据 * * @return */ public static ArrayList<ChargeRecordsInfo> getStorageEntities(String fileName) { ObjectInputStream objectInputStream = null; FileInputStream fileInputStream = null; ArrayList<ChargeRecordsInfo> savedArrayList = new ArrayList<>(); try { File file = new File(AppContext.getFilesDir().getAbsoluteFile(), fileName); fileInputStream = new FileInputStream(file.toString()); objectInputStream = new ObjectInputStream(fileInputStream); savedArrayList = (ArrayList<ChargeRecordsInfo>) objectInputStream.readObject(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (objectInputStream != null) { objectInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } return savedArrayList; } /** * 获取本地的List数据 * * @return */ public static ArrayList<Integer> getStorageEntitiesSpinner(String fileName) { ObjectInputStream objectInputStream = null; FileInputStream fileInputStream = null; ArrayList<Integer> savedArrayList = new ArrayList<>(); try { File file = new File(AppContext.getFilesDir().getAbsoluteFile(), fileName); fileInputStream = new FileInputStream(file.toString()); objectInputStream = new ObjectInputStream(fileInputStream); savedArrayList = (ArrayList<Integer>) objectInputStream.readObject(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (objectInputStream != null) { objectInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } return savedArrayList; }}
阅读全文
0 1
- List集合存储到本地
- Android将list数据通过LitePal保存到本地(集合保存到本地)
- Android将list数据通过LitePal保存到本地(集合保存到本地)
- Android 使用LitePal将list(String,对象,集合)数据保存到本地数据库
- Redis存储List<T>集合
- GreenDao存储list集合数据
- UNITY存储图片到本地
- 存储图片到本地、提取本地存储的图片
- * 需求:List集合存储字符串并遍历。
- map 集合中存储list ,class
- List集合存储学生对象并遍历
- 存储过程的导入List<Object>集合
- 使用LitePal存储list集合数据
- 使用GreenDao存储list集合数据
- mybatis将list集合插入到数据库
- 本地图片存储到oracle数据库中
- php获取远程图片存储到本地
- 数据持久化--数据存储到本地
- ArcEngine保存为mxd的方法
- <<High-Speed Tracking with Kernelized Correlation Filters>> KCF(核化相关滤波)跟踪算法学习笔记
- 软件架构的概念(2)
- 八种排序算法Java实现-快速排序
- hdu1412 {A}+{B}
- List集合存储到本地
- Docker端口映射
- mysql中的coalesce用法
- PostgreSQL模式详解
- vim编辑器常用的基本使用方式
- springMvc四种处理器映射器之二:SimpleUrlHandlerMapping
- 深复制和浅复制
- Android java 遍历Map的四种方法
- 生产者和消费者线程实现