Monday 15 April 2013

java - Writing Data Structures to files using FileOutputStream? -


I have an Android application and I have to store / retrieve a data structure in memory which I use onpause () / OnResume is built on () methods so that between data runs continue through FileOutputStream / FileInputStream, which is standard practice for this

So, how can I save the data structure in a file so that I Can get later (I have seen an example of doing this with string But not other objects)? Do I have been forced to create a getBytes () function and the subsequent object for my data structure, in addition to creating a constructor for all these objects that makes them with the bit array?

Edit: Ah, okay; Hence it is called serialization. Is the following right?

To write:

  fileoptrast fileout = new file optup stream ("file name"); ObjectOutputStream Out = New ObjectOutputStream (FileAut); Out.writeObject (E); Out.close (); FileOut.close ();   

To read:

  FileInputStream fileIn = New FileInputStream ("filename"); ObjectInputStream = In New ObjectInputStream (fileIn); E = (object type) in.readObject (); In.close (); FileIn.close (); Editing 2: In addition, the data structure and the inherent objects (and sub-objects) should apply to serial jabbs. For example, if I had a BST of dogs, then I would like to prepare BST, Arrayist, and Dog Class for serialization and then call the above works.  

Is all this right?

See in SerialJase Library it allows you to write a class directly into a non-human readable file , Then can be read back in the same way.

No comments:

Post a Comment