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

📄 readobject.java

📁 疯狂Java讲义_源码(含Java设计模式CHM
💻 JAVA
字号:
import java.io.*;

/**
 * Description:
 * <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author  Yeeku.H.Lee kongyeeku@163.com
 * @version  1.0
 */
public class ReadObject
{
	public static void main(String[] args) 
	{
		ObjectInputStream ois = null;
		try
		{
			//创建一个ObjectInputStream输出流
			ois = new ObjectInputStream(
				new FileInputStream("object.txt"));
			//从输入流中读取一个Java对象,并将其强制类型转换为Person类
			Person p = (Person)ois.readObject();
			System.out.println("名字为:" + p.getName()
				+ "\n年龄为:" + p.getAge());
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if (ois != null)
					ois.close();
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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