public class Test {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Student stu1 = new Student("张三",19);
Student stu2 = new Student("李四",20);
LinkedList link = new LinkedList();
link.add(stu1);
link.add(stu2);
try {
//问题就在这哈! 我想打开1.txt的时候不是显示字节码,而是字符!请大
大哥大姐姐帮帮忙哈!
FileOutputStream os = new FileOutputStream("1.txt");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(link);
oos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Student stu1 = new Student("张三",19);
Student stu2 = new Student("李四",20);
LinkedList link = new LinkedList();
link.add(stu1);
link.add(stu2);
try {
//问题就在这哈! 我想打开1.txt的时候不是显示字节码,而是字符!请大
大哥大姐姐帮帮忙哈!
FileOutputStream os = new FileOutputStream("1.txt");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(link);
oos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
那你应该以字节的方式写入文件。你的代码中只是把对象序列化文件,这样肯定是二进制的玩意,这样的好处是反序列化比较容易,可以直接读取到Object。