序列化时用的TXT,能正常读出来,但是TXT里面是乱码

package com.zb.iolist;


import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.OutputStream;


public class StudentSerial {


public static void main(String[] args) throws Exception{

String file = "accessFile\\输入测试.txt";

//对象的序列化

ObjectOutputStream oos = new ObjectOutputStream(

new FileOutputStream(file));

Student stu1 = new Student("1221010433", "嘿嘿", 24);

oos.writeObject(stu1);

oos.flush();

oos.close();

//以上程序会因为Student没有实现Serializable接口儿抛出异常

//对象的反序列化

ObjectInputStream ois = new ObjectInputStream(

new FileInputStream(file));

Student stu2 = (Student) ois.readObject();

System.out.println(stu2);

ois.close();

}


}


super5hong
浏览 1581回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java