本帖最后由 Friendy89 于 2013-8-8 12:24 编辑
用IO流网文件中写对象是怎么写入多个对象,我怎么只能写入一个对象- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import IO.P4.Print.Person;
- public class ObjectStreamDemo {
- public static void main(String[] args) throws IOException, ClassNotFoundException {
- writeObj();
- }
- //对象序列化
- public static void writeObj() throws IOException, IOException {
- ObjectOutputStream oos =
- new ObjectOutputStream(new FileOutputStream("src\\IO\\tempfile\\obj.txt"));
- oos.writeObject(new Person("lisi",23));//<FONT color=red>如果还要继续添加对象应该怎么写
- </FONT> oos.close();
- }
- }
复制代码 |