

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class RecordDao {
	private String fileName;
	public RecordDao(){
		fileName = "record/record.dat";
	}
	/**
	 * ļжȡһRecord
	 * @return  Record
	 */	
	public Record readRecord(){
		FileInputStream  fis=null;
		ObjectInputStream ois=null;
		Record record = null;
		try {
			fis = new FileInputStream(fileName);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
		try {
			ois = new ObjectInputStream(fis);
			record = (Record) ois.readObject();
		} catch (IOException e) {
			e.printStackTrace();
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		}finally{
			try {
				ois.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				fis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return record;
	}
	
	/**
	 * ļһRecord
	 */
	public void writeRecord(Record record){
		FileOutputStream  fos=null;
		ObjectOutputStream oos=null;
		try {
			fos = new FileOutputStream(fileName);
			oos = new ObjectOutputStream(fos);
			oos.writeObject(record);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}catch(IOException e){
			e.printStackTrace();
		}
		finally{
			try {
				oos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				oos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
