读对象数据流 Java 出错代码
import java.io.*;
import java.util.*;
public class Test{
public static void main(String[] args) throws IOException{
/* Date d=new Date();
FileOutputStream f=new FileOutputStream("date.txt");
ObjectOutputStream s=new ObjectOutputStream(f);
try{
s.writeObject(d);
s.close();
}catch(IOException e){
e.printStackTrace();
}
*/
Date d=null;
FileInputStream f=new FileInputStream("date.ser");
ObjectInputStream s=new ObjectInputStream(f);
try{
d = (Date)s.readObject(d);//此处错误提示The method readObject() in the type s.close();
}catch(IOException e){ //ObjectInputStream is not applicable for the arguments (Date)
e.printStackTrace();
}
System.out.println("date at"+d);
}
}
没有评论:
发表评论