Коллеги, помогите разобраться с задачей. Вроде все условия выполнил, но успешно завершить выполнение задачи никак не могу. Помогите бедному студенту :)))))
package com.javarush.task.task20.task2022;
import java.io.*;
/*
Переопределение сериализации в потоке
*/
public class Solution implements Serializable, AutoCloseable {
private transient FileOutputStream stream;
private String fileName;
public Solution(String fileName) throws FileNotFoundException {
this.fileName = fileName;
this.stream = new FileOutputStream(fileName);
}
public Solution() {
}
public void writeObject(String string) throws IOException {
stream.write(string.getBytes());
stream.write("\n".getBytes());
stream.flush();
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(fileName);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
//Object obj = in.readObject();
fileName = (String)in.readObject();
stream = new FileOutputStream(fileName,true);
}
@Override
public void close() throws Exception {
System.out.println("Closing everything!");
stream.close();
}
public static void main(String[] args) throws Exception {
Solution solution = new Solution("C:/учеба/files/task2022.txt");
ObjectOutputStream outputStream = new ObjectOutputStream(solution.stream);
solution.writeObject(outputStream);
Solution solutionOut = new Solution();
FileInputStream fiStream = new FileInputStream("C:/учеба/files/task2022.txt");
solutionOut.readObject(new ObjectInputStream(fiStream));
ObjectOutputStream outputStreamOut = new ObjectOutputStream(solutionOut.stream);
solution.writeObject(outputStreamOut);
solution.close();
solutionOut.close();
}
}