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

📄 objectio.java.bak

📁 考试系统
💻 BAK
字号:
/*
 * Created on 2004-4-29
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package io;
import java.io.*;

/**
 * @author SpiritRain
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public abstract class ObjectIO {
	private Object obj;
	private String fileName;
	private static String path = "lib\\";
	private ObjectInputStream in;
	private ObjectOutputStream out;

	public void read() {
		try {
			in = new ObjectInputStream(new FileInputStream("lib\\" + fileName));
			obj = in.readObject();
			in.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void write() {
		try {
			out =
				new ObjectOutputStream(
					new FileOutputStream("lib\\" + fileName));
			out.writeObject(obj);
			out.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void setFileName(String fname) {
		this.fileName = fname;
	}

	public Object getObject() {
		return this.obj;
	}

	/**
	 * 
	 */
	public static Object read(String fileName) {
		Object obj = null;
		try {
			ObjectInputStream in =
				new ObjectInputStream(new FileInputStream(path + fileName));
			obj = in.readObject();
			in.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			return obj;
		}
	}

	/**
	 * 
	 */
	public static void write(Object obj, String fileName) {
		try {
			ObjectOutputStream out =
				new ObjectOutputStream(
					new FileOutputStream(path + fileName));
			out.writeObject(obj);
			out.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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