fork download
  1. import java.io.*;
  2. class serialization {
  3. public static void main(String[] args) {
  4. try {
  5. Myclass object1 = new Myclass("Hello", -7, 2.1e10);
  6. FileOutputStream fos = new FileOutputStream("serial");
  7. oos.writeObject(object1);
  8. oos.flush();
  9. oos.close();
  10. }
  11. catch(Exception e) {
  12. System.out.println("Serialization" + e);
  13. System.exit(0);
  14. }
  15. try {
  16. int x;
  17. FileInputStream fis = new FileInputStream("serial");
  18. x = ois.readInt();
  19. ois.close();
  20. System.out.println(x);
  21. }
  22. catch (Exception e) {
  23. System.out.print("deserialization");
  24. System.exit(0); }
  25. }
  26. }
  27. class Myclass implements Serializable {
  28. String s;
  29. int i;
  30. double d;
  31. Myclass(String s, int i, double d){
  32. this.d = d;
  33. this.i = i; this.s = s;
  34. }
  35. }
  36.  
  37.  
Success #stdin #stdout 0.12s 51280KB
stdin
Standard input is empty
stdout
Serializationjava.io.FileNotFoundException: serial (Permission denied)