DVD项目功能实现

上传:qq_29796440 浏览: 40 推荐: 0 文件:DOCX 大小:25.49MB 上传时间:2018-12-14 14:00:38 版权申诉
package com.lanying.dao.impl; import java.io.*; import java.util.ArrayList; import java.util.List; public class BaseDaoImpl { protected List read(File file) { FileInputStream fis = null; ObjectInputStream ois = null; List list = new ArrayList(); try { if(!file.exists()){ file.createNewFile();// 首次运行,文件不存在,需要自动创建 } fis = new FileInputStream(file); ois = new ObjectInputStream(fis) ; list = (List) ois.readObject();// 第一次运行时,文件中没有数据,会抛异常 EOF } catch(EOFException e){ System.err.println("首次运行,不要紧张"); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } if(ois != null){ try { ois.close(); } catch (IOException e) { e.printStackTrace(); } } return list; } protected boolean write(List list, File file) { FileOutputStream fos = null; ObjectOutputStream oos = null; try { fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeObject(list); return true; } catch (IOException e) { e.printStackTrace(); } finally { if(oos != null){ try { oos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; } }
上传资源
用户评论