• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to append List Objects in File  RSS feed

 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing menu based application for register event in java. In each session user able to register people in event. So it create a list of all registered users and serialize these list objects onto a file. And there is view people show all the registered users. Problem is once the user gets registered for one session, remains as it is when i select view people even if i added some new people in new session. Here is my method to save List

Here is method for deserialize :


Any Idea how can i store/append multiple lists in file and during deserialization can show all records.

Thanks
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can append to an Object file.
Work arounds:
* Always keep a list of RegisterParty and write the entire list to a file. This means that to add a party you'd first have to read the entire existing list into memory first.
* Use a database of RegisterParty.
* Use random access file where you write 4 bytes containing the size of your object record, followed by the object record. In this manner you can append to the file or find a record by hopping the number of bytes in each entry.
 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:I don't think you can append to an Object file.
Work arounds:
* Always keep a list of RegisterParty and write the entire list to a file. This means that to add a party you'd first have to read the entire existing list into memory first.
.


Here i create the list of ResisterParty and write then over the file? So shall i keep the same file, as i want all records to be tracked. When i'll restart the application the I would write more list over the file. I that case if i want to display all list, How can i Do that?

Thanks
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vivek dhiman wrote:
Carey Brown wrote:I don't think you can append to an Object file.
Work arounds:
* Always keep a list of RegisterParty and write the entire list to a file. This means that to add a party you'd first have to read the entire existing list into memory first.
.


Here i create the list of ResisterParty and write then over the file? So shall i keep the same file, as i want all records to be tracked. When i'll restart the application the I would write more list over the file. I that case if i want to display all list, How can i Do that?

Thanks

You will need something like List<RegisterParty>, then a method to load the list from the file, then display or add to the list, and finally, write (overwite) the list to the file. You can display all the entries by iterating over the list: for( RegisterParty rp : list ).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!