为什么输出是null
package Externalizable;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public class Person implements Externalizable {
private String name;
private int age;
public Person(){
}
public Person(String name, int age){
this.name = name;
this.age = age;
}
public String toString(){
return "姓名: " +this.name + " 年龄" + this.age;
}
//只写或读 下面的东西
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.name);
out.writeObject(age);
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.name = (String)in.readObject();
this.age = in.readInt();
}
}
-----------------------------------------------------------------------------------
package Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import Transirnt.Person;
public class Externalizabletest {
public static void main(String[] args) {
ser();
dser();
}
private static void ser() {
File f = new File("e:/" + File.separator + "tes.txt");
try {
ObjectOutputStream oos = null;
OutputStream out = new FileOutputStream(f);
oos = new ObjectOutputStream(out);
oos.writeObject(new Person("lkkj", 12));
// System.out.println();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void dser() {
try {
File f = new File("e:/" + File.separator + "tes.txt");
ObjectInputStream ois = null;
InputStream input = new FileInputStream(f);
ois = new ObjectInputStream(input);
Object obj = ois.readObject();
ois.close();
System.out.println(obj);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
求大神帮助。。。
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public class Person implements Externalizable {
private String name;
private int age;
public Person(){
}
public Person(String name, int age){
this.name = name;
this.age = age;
}
public String toString(){
return "姓名: " +this.name + " 年龄" + this.age;
}
//只写或读 下面的东西
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(this.name);
out.writeObject(age);
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
this.name = (String)in.readObject();
this.age = in.readInt();
}
}
-----------------------------------------------------------------------------------
package Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import Transirnt.Person;
public class Externalizabletest {
public static void main(String[] args) {
ser();
dser();
}
private static void ser() {
File f = new File("e:/" + File.separator + "tes.txt");
try {
ObjectOutputStream oos = null;
OutputStream out = new FileOutputStream(f);
oos = new ObjectOutputStream(out);
oos.writeObject(new Person("lkkj", 12));
// System.out.println();
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void dser() {
try {
File f = new File("e:/" + File.separator + "tes.txt");
ObjectInputStream ois = null;
InputStream input = new FileInputStream(f);
ois = new ObjectInputStream(input);
Object obj = ois.readObject();
ois.close();
System.out.println(obj);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
求大神帮助。。。

...全文
相关推荐
JavaScript undefined及null区别实例解析
例如:```javascriptvar car = null;console.log(car === null); // 输出:true```在处理对象时,如果你希望一个变量表示尚未分配对象的引用,初始化为
git报错需要的null.sys
在Git中,`/dev/null`可能被用作某些内部操作的输出重定向。首先,我们需要理解为什么Git会尝试操作`/dev/null`。
sql 语句中的 NULL值
这就是为什么在最初的例子中,`IF(@atr = NULL)`不会执行打印1的操作。
MySQL中count(*)、count(1)和count(col)的区别汇总
由于具体字段的实际情况未知,这里无法精确解释为什么是33,但通常键长度会反映索引实际占用的空间。5.
为什么要使用PHP单例模式及应用实例.docx
这有助于设置调试钩子和输出日志,简化了调试流程,提高了效率。- **避免过度输出**:通过在单例类中设置日志输出功能,可以避免在代码各处使用`var_dump`或`echo`等命令,使代码更加整洁。


