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

📄 objectio.java

📁 考试系统
💻 JAVA
字号:
package io;
import java.io.*;

/**
 * @author SpiritRain
 * 
 * a simple io class to read and write object
 */
public abstract class ObjectIO {
	private static String path = "lib\\";

	/**
	 * read an object from a file
	 * @param fileName file name
	 * @return object
	 */
	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;
		}
	}

	/**
	 * write an object to a file
	 * @param obj object to be writed
	 * @param fileName target file name
	 */
	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 + -