как понять , что отрабатывает тот самый восстановленный поток FileOutputStream ?
то что в файл у меня дописывается MoreString ? то есть поток видит тот путь к файлу, указанный в начале? в строке
Solution sol=new Solution("O://1.txt");
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 void writeObject(String string) throws IOException {
stream.write(string.getBytes());
stream.write("\n".getBytes());
stream.flush();
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
this.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 IOException, ClassNotFoundException {
Solution sol=new Solution("O://1.txt");
sol.writeObject("MyString");
ByteArrayOutputStream aOut=new ByteArrayOutputStream();
ObjectOutputStream oOut=new ObjectOutputStream(aOut);
oOut.writeObject(sol);
ByteArrayInputStream aIn=new ByteArrayInputStream(aOut.toByteArray());
ObjectInputStream oIn=new ObjectInputStream(aIn);
Solution sol2=(Solution) oIn.readObject();
sol2.writeObject("MoreString");
}
}