import java.io.*; public class Main implements Serializable { private int width; private int size; public void setWidth(int width) { this.width = width; } public void setSize(int size) { this.size = size; } public static void main(String[] args) { Main m = new Main(); m.setWidth(22); m.setSize(84); try { FileOutputStream fileOut = new FileOutputStream("andriy.ser"); ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); objectOut.writeObject(objectOut); objectOut.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } UPD. Missed that it was necessary to transfer the link to a copy of the class Main
ObjectOutputStream does not implement Serializable, so probably. In general, the string objectOut.writeObject (objectOut); looks weird. - zRrr