-2

私は次のようになっています:

java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at com.Temp.main(Temp.java:62)

以下は、実行しようとしているコードです。

class Dog implements Serializable {
    private static final long serialVersionUID = 1L;
    int age = 0;
    String color = "Black";
}

public class Temp {
    public static void main(String[] args) {
        FileOutputStream fos;
        ObjectOutputStream oos;
        FileInputStream fis;
        ObjectInputStream ios;
        File doggy;
        try {
            Dog fluffy = new Dog();
            fos = new FileOutputStream("DOG_store.txt");
            oos = new ObjectOutputStream(fos);
            oos.writeObject(fluffy);
            fos.close();
            oos.close();

            doggy = new File("DOG_store.txt");
            FileWriter fw = new FileWriter(doggy); // **This is Causing ISSUE**

            fis = new FileInputStream("DOG_store.txt");
            ios = new ObjectInputStream(fis);
            Dog scrappy = (Dog) ios.readObject();
            fis.close();
            ios.close();
            System.out.println(scrappy.age + " " + scrappy.color);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (ClassNotFoundException cfne) {
            cfne.printStackTrace();
        }
    }
4

1 に答える 1