如何创建对象序列化? [英] How to create object serialization?
本文介绍了如何创建对象序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码没有运行,它在线上给出错误java 18 error
the code is not running, its giving error on line "java 18 error"
FileInputStream t=new FileInputStream("f:\\tj.txt");
我尝试过:
What I have tried:
package serial;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class MainSerial {
public static void main(String[] args) throws IOException, ClassNotFoundException {
student x=new student();
x.name="abc";
x.address="xyz";
x.phonenumber="213123";
FileOutputStream p=new FileOutputStream("d:\\tj.txt");
ObjectOutputStream pp=new ObjectOutputStream(p);
pp.writeObject(x);
FileInputStream t=new FileInputStream("d:\\tj.txt");
ObjectInputStream tt=new ObjectInputStream(t);
student ll=(student) tt.readObject();
System.out.println(ll.name);
System.out.println(ll.address);
System.out.println(ll.phonenumber);
// TODO Auto-generated method stub
}
}
"serial class"
package serial;
import java.io.Serializable;
public class student implements Serializable {
String name;
String address;
String phonenumber;
}
推荐答案
如果您说错误是
18:错误:找不到符号
它告诉你它不知道FileInputStream是什么。
首先,摆脱代码顶部的import java.io.whatevers;块并将其替换为一行:
If you're saying that the error is
"18: error: cannot find symbol"
It's telling you that it doesn't know what FileInputStream is.
First, get rid of that block of "import java.io.whatevers;"at the top of your code and replace it with a single line:
import java.io.*;
这篇关于如何创建对象序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文