View Single Post
  #1 (permalink)  
Old 07-16-2007, 06:28 PM
paul paul is offline
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
Java serialization
I'm trying to learn java serialization, and I tried a code just like the one on this page
So I created my own code with my own objects.
The problem is that I specified to save the data into a file named "Inv.dat".
I have never actually seen that file being created, but, since I'm able to print the objects I added on the Write class from the Read class, my code works.
Code:
public class Write{ public Write(){ String filename = "Inv.dat"; inventory.Inventory storeA = new inventory.Inventory (); ...... try{ FileOutputStream fos = new FileOutputStream(filename); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(storeA); out.close(); }// end try ......
Code:
public class Read{ public static void main(String[] args){ String filename = "Inv.dat"; FileInputStream fis = null; ObjectInputStream ois = null; inventory.Inventory storeA = null; try{ fis = new FileInputStream(filename); ois = new ObjectInputStream(fis); storeA = (inventory.Inventory)ois.readObject(); }//end try ..... System.out.println(storeA); .....
Does this mean Inv.dat has been created somewhere where I don't see it?
If so, where is Inv.dat being created or saved?

Ah, never mind, I found it, now the question is why did it save it there? I've got the following directories:

MyDocuments > Java > CS211 > lab9 > persist
presist contains the Read/Write classes, and lab9 contains 2 other classes that create the objects. Inv.dat was created on the CS211 directory.
Thanks
Reply With Quote
Sponsored Links