展开全部
下面方法源于JDK API官方文档public final void writeObject(Object obj) throws IOException
将指定的对象写入 ObjectOutputStream,obj - 要写入的对象
对于将62616964757a686964616fe59b9ee7ad9431333363396436内容写到的位置,取决于其文件输出流。下面例子供参考:public class Employee implements Serializable {
String name;
int age;
public Employee(String name, int age) {
super();
this.name = name;
this.age = age;
}
public void aa(Employee employee) throws Exception {
// 文件输出流指定输出的位置(与系统有关的文件名)
FileOutputStream fos = new FileOutputStream("e:/person.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
// 要写入的对象
oos.writeObject(employee);
}
public static void main(String[] args) {
Employee employee = new Employee("张三", 20);
try {
employee.aa(employee);
} catch (Exception e) {
e.printStackTrace();
}
}
}