62,616
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
public class SerialTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Employee e1 = new Employee( " zhangsan " , 25 , 3000.50 );
Employee e2 = new Employee( " lisi " , 24 , 3200.40 );
Employee e3 = new Employee( " wangwu " , 27 , 3800.55 );
FileOutputStream fos = new FileOutputStream("employee.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(e1);
oos.writeObject(e2);
oos.writeObject(e3);
oos.close();
FileInputStream fis = new FileInputStream("employee.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Employee e;
for ( int i = 0 ;i < 3 ;i ++ )
{
e = (Employee)ois.readObject();
System.out.println(e.name + " : " + e.age + " : " + e.salary);
}
ois.close();
}
}
class Employee implements Serializable{
String name;
int age;
double salary;
transient Thread t = new Thread();
public Employee(String name, int age, double salary)
{
this .name = name;
this .age = age;
this .salary = salary;
}
private void writeObject(java.io.ObjectOutputStream oos) throws IOException
{
oos.writeInt(age);
oos.writeUTF(name);
System.out.println( " Write Object " );
}
private void readObject(java.io.ObjectInputStream ois) throws IOException
{
age = ois.readInt();
name = ois.readUTF();
System.out.println( " Read Object " );
}
}
比如这段代码,请问在序列化后写入硬盘上时,是按照什么编码格式呢?
是unicode么?