Всё считывается, почему не проходит?
package com.javarush.task.task20.task2011;
import java.io.*;
/*
Externalizable для апартаментов
*/
public class Solution {
public static class Apartment implements Externalizable {
private String address;
private int year;
/**
* Mandatory public no-arg constructor.
*/
public Apartment() {
super();
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(address);
out.writeObject(year);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
address = (String) in.readObject();
year = (int) in.readObject();
}
public Apartment(String addr, int y) {
address = addr;
year = y;
}
/**
* Prints out the fields used for testing!
*/
public String toString() {
return ("Address: " + address + "\n" + "Year: " + year);
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
Apartment app = new Apartment("Kalinina", 100);
FileOutputStream fileOutputStream = new FileOutputStream("D:\\Test.txt");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
app.writeExternal(objectOutputStream);
Apartment load = new Apartment();
FileInputStream fileInputStream = new FileInputStream("D:\\Test.txt");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
load.readExternal(objectInputStream);
System.out.println(app);
System.out.println(load);
System.out.println(app.equals(load));
}
}