Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package menu;
- import java.io.*;
- class Cat implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = -6226623636109879891L;
- String teste = "sfasdfsfd";
- } // 1
- class SerializeCat {
- public static void main(String args[]) {
- Cat c = new Cat(); // criando o objeto
- // aqui vou serializar meu objeto da class cat
- try {
- FileOutputStream fo = new FileOutputStream("test.ser");
- ObjectOutputStream oo = new ObjectOutputStream(fo);
- oo.writeObject(c); // serializo objeto cat
- oo.close();
- System.out.println("Class Cat - object serializado com sucesso");
- } catch (Exception e) {
- e.printStackTrace();
- }
- // des-serializo o objeto
- try {
- FileInputStream fi = new FileInputStream("test.ser");
- ObjectInputStream oi = new ObjectInputStream(fi);
- c = (Cat) oi.readObject();
- oi.close();
- System.out.println("agora ele foi des-serializado com sucesso");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement