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

📄 defaultserial.java

📁 《Java语言程序设计》源代码 很好的JAVA入门的好的代码
💻 JAVA
字号:
import java.io.*;
import java.awt.Color;
class Bag implements Serializable{
	Color color;
	String price;
	int size;
	String type;
	public Bag(Color color,String price,int size,String type){
		this.color = color;
		this.price = price;
		this.size = size;
		this.type = type;
	}
}
public class DefaultSerial{
	public static void main(String args[])throws IOException,ClassNotFoundException{
		Color c = Color.red;
		Bag bag = new Bag(c,"57",18,"Student bag");
		FileOutputStream fileO = new FileOutputStream("info.ser");
		ObjectOutputStream OS = new ObjectOutputStream(fileO);
		try
		{
			OS.writeObject(bag);
			OS.close();
		}catch(IOException e)
		{
			System.out.println(e);
		}
		bag = null;
		FileInputStream fileI = new FileInputStream("info.ser");
		ObjectInputStream IS =null;
		IS = new ObjectInputStream(fileI);
		try
		{
			bag = (Bag)IS.readObject();
			IS.close();
		}catch(IOException e)
		{
			System.out.println(e);
		}
		System.out.println("*********************************");
		System.out.println("There are information about bag:");
		System.out.println("Color:"+bag.color);
		System.out.println("Price:"+bag.price);
		System.out.println("Size:"+bag.size);
		System.out.println("Type:"+bag.type);
		System.out.println("*********************************");
	}
}

⌨️ 快捷键说明

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