标签:transient
public class TransientDemo implements Serializable{结果密码输出为null
/**
*
*/
private static final long serialVersionUID = 1L;
private transient String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
// TODO Auto-generated method stub
String path="D:"+File.separator+"object.txt";
File file=new File(path);
TransientDemo transientDemo=new TransientDemo();
transientDemo.setName("姓名");
transientDemo.setPassword("密码");
ObjectOutput output=new ObjectOutputStream(new FileOutputStream(file));
output.writeObject(transientDemo);
ObjectInput input=new ObjectInputStream(new FileInputStream(file));
TransientDemo demo=( TransientDemo )input.readObject();
System.out.println(demo.getName()+demo.getPassword());
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:transient
原文地址:http://blog.csdn.net/qq924862077/article/details/48022203