欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java之IO流

程序员文章站 2024-03-05 15:22:25
...
/*把字符串数组以类对象的格式保存到文件中(院系代码.txt),再从文件中读取数据,到指定的类对象*/
import java.io.*;
public class text10
{
    public static void main(String []args) throws Exception
    {
        FileReader reader = new FileReader("school.txt");
        int ch;
        int i = 0;
        char []a = new char[1024];
        while ((ch = reader.read()) != -1) 
        { 
            if((char)ch != '\n')
            System.out.print((char)ch);
            else
            System.out.println();
        }
        Person p = new Person((char)a[i]);
        FileOutputStream fos = new FileOutputStream("LJ.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(p);
        FileInputStream fis = new FileInputStream("LJ.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        ois.readObject();
    }
}
class Person implements Serializable
{
    char id;
    public Person(char id)
    {
        super();
        this.id = id;
    }
    public char getId()
    {
        return id;
    }

}

Java之IO流

相关标签: java

上一篇: JQuery 三级联动

下一篇: