主题:[讨论]该错题,你知道吗?
请各位高手帮我改一下代码
大体思路看程序
package jh;
import java.io.*;
class Student{
String id;
String age;
String department;
String name;
Student(String id,String age,String department,String name){
this.id = id;
this.age = age;
this.department = department;
this.name = name;
}
}
/**
* @param args
*/
public class TestInput {
public static void main(String[] args) {
FileInputStream fi = null;
ObjectInputStream si = null;
Student stu = null;
try {
fi = new FileInputStream("text.txt");
si = new ObjectInputStream(fi);
stu = (Student) si.readObject();
si.close();
System.out.print("student stu : id " + stu.id);
System.out.print("student stu : age " + stu.age);
System.out.print("student stu : department" + stu.department);
System.out.print("student stu : name" + stu.name);
}catch(StreamCorruptedException a)
{
a.printStackTrace();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
大体思路看程序
package jh;
import java.io.*;
class Student{
String id;
String age;
String department;
String name;
Student(String id,String age,String department,String name){
this.id = id;
this.age = age;
this.department = department;
this.name = name;
}
}
/**
* @param args
*/
public class TestInput {
public static void main(String[] args) {
FileInputStream fi = null;
ObjectInputStream si = null;
Student stu = null;
try {
fi = new FileInputStream("text.txt");
si = new ObjectInputStream(fi);
stu = (Student) si.readObject();
si.close();
System.out.print("student stu : id " + stu.id);
System.out.print("student stu : age " + stu.age);
System.out.print("student stu : department" + stu.department);
System.out.print("student stu : name" + stu.name);
}catch(StreamCorruptedException a)
{
a.printStackTrace();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}