package demo1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
public class StuR implements java.io.Serializable{
ArrayList <ProductRecoder> ax=new ArrayList<ProductRecoder>();
File file = new File("d:/productrecoder.txt");
//添加
public void adds(ProductRecoder s){
ax.add(s);
}
public void paint(){
for(int i=0;i<ax.size();i++)
{
System.out.println(ax.get(i));
}
}
public String toString()
{
return "StuC [al=" + ax + "]";
}
//输出流
public void stor1() {
ObjectOutputStream out = null;
try {
out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(ax);
out.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
//输入流
public void read()
{
ObjectInputStream in = null;
try {
in = new ObjectInputStream(new FileInputStream(file));
try
{
ax = (ArrayList<ProductRecoder>)in.readObject();
}
catch (ClassNotFoundException e) {
ax=null;
}
in.close();
}
catch (FileNotFoundException e) {
File file = new File("d:/productrecoder.txt");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
到底是怎么回事啊,我在百度上找有人说,是没有实现java.io.Serializable实现之后还是解决不了问题,还是会抛出java.io.NotSerializableException求大神指教?
添加回答
举报
0/150
提交
取消