• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializing an Object in Java ? How do i reuse it the object and where can i !  RSS feed

 
Matt Swaggi
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends !
i am getting the output to the code which i am going to stated below but where do i exactly find the object and how come i re-use it !

Code:

import java.io.*;

public class SerializingObject{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter File name : ");
String file = in.readLine();
System.out.print("Enter extention : ");
String ext = in.readLine();
String filename = file + "." + ext;
File f = new File(filename);
ObjectOutput ObjOut = new ObjectOutputStream(new FileOutputStream(f));
ObjOut.writeObject(f);
ObjOut.close();
System.out.println("Serializing an Object Creation is completly Successfully.");
}
}


Output:

Please enter File name : Filterfile
Enter extention : txt
Serializing an Object Creation is completly Successfully.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should find it in the directory from where you're running this code. Note that serialized objects are binary, not text - so a file extension "txt" is not appropriate.

You can later use it by deserializing the object. See examples e44 and e45 here.
 
Matt Swaggi
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You sir
I will try the examples and catch you soon !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!