会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132376个问题

image.png

Python 全系列/第二阶段:Python 深入与提高/坦克大战 646楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/GraphQL 649楼

Student.txt

Test.txt

package zhang;

import java.io.Serializable;

public class Student implements Serializable  {
    /**
     * 
     */
    private static final long serialVersionUID = -4502633718082654465L;
    private String name;
    private int age;
    public static String schoolName;//学校名称
    private transient String pwd; //属性的值将不再被序列化
    public Student() {
        super();
    }
    public Student(String name, int age, String pwd) {
        super();
        this.name = name;
        this.age = age;
        this.pwd = pwd;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "Student [name=" + name + ", age=" + age + ", pwd=" + pwd + "]"+"schoolName="+schoolName;
    }
    
    
}
package zhang;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TEST {
    public static void write() throws Exception, IOException
    {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E://Data.txt"));
        Student s = new Student("zhang",20,"121");
        s.schoolName="BJ";
        oos.writeObject(s);
        oos.close();
    }
    
    public static void read() throws Exception, IOException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:\\Data.txt"));
        Student s = (Student)ois.readObject();
        ois.close();
        System.out.println(s);
    }
    public static void main(String[] args) throws IOException, Exception {
        write();
        read();
    }
}

图片.png

老师,我这个不知道哪里错了,静态的schoolName 有显示

JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 652楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 653楼
Python 全系列/第一阶段:Python入门/编程基本概念 655楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 659楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637