View Single Post
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Modifying a file.

 
0
  #6
Nov 22nd, 2008
Originally Posted by stephen84s View Post
Just a thought, instead of writing each object after serializing one by one to the file, why don't you just serialize the entire ArrayList and write it to a file.
And when you need to add any data to the file, get the ArrayList back from the file, add the object to the ArrayList and serialize this ArrayList overwrite the file with the older file.
Unfortunately, the implementation of ArrayList<T> looks [something] like this--

  1. //... necessary imports
  2.  
  3. public class ArrayList<T> extends List<T> implements Collection<T>, Serializable{
  4.  
  5. private transient Object[] elements = null; // key point @_@
  6.  
  7. public T get(int position){
  8. return (T)elements[position];
  9. }
  10. }
Reply With Quote