⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountfiledao.java

📁 这个小的系统是使用java语言编写的一个银行类的小程序
💻 JAVA
字号:
package dao.impl;
import java.io.*;
import java.util.*;

import dao.AccountDao;
import model.Account;
public class AccountFileDao implements AccountDao {
	private String name;
	
	
	public AccountFileDao(String name) {
		super();
		this.name = name;
	}

	public void saveAccounts(Map m){
		ObjectOutputStream out=null;
		try {
			FileOutputStream fos=new FileOutputStream(name);
			out = new ObjectOutputStream(fos);
			
			Collection c=m.values();
			Iterator it=c.iterator();
			while(it.hasNext()){
				Account ac=(Account)it.next();
				out.writeObject(ac);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		finally{
			try {
				if (out!=null) out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Map loadAccounts(){
		Map m=new HashMap();
		ObjectInputStream in=null;
		try {
			FileInputStream fis=new FileInputStream(name);
			in = new ObjectInputStream(fis);
			while(true){
				Account ac=(Account)in.readObject();
				m.put(new Long(ac.getId()),ac);
			}
		} catch (IOException e) {
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		finally{
			try {
				if (in!=null) in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		return m;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -