Results 1 to 7 of 7
- 04-20-2011, 05:37 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
How to access all the datafields of a class?
I have some classes like Client, Employee, Property
I am maintaining the list of all the objects as array lists in a class names NIC.
So class NIC is like
class NIC
{
static ArrayList<Employee> employeeList = new ArrayList<Employee>();
static ArrayList<Property> propertyList = new ArrayList<Property>();
static ArrayList<Client> clientList = new ArrayList<Client>();
//rest of the code
public static void backItUp()
{
//this method reads all the objects data from array lists and stores it in a file
}
}
--------------------------------------------
I am stuck on the method backItUp() which is supposed to read all the objects data from array list and store it in a file.
I don't know if there is any method which can access all the data fields of current class or at least returns a reference of each data field.
Please help. Thanks in advance.
-
you don't need to do that, just serialize the object and write the entire object to a file. when you need the data, load the object and access its fields as you would normally.
http://java.sun.com/developer/techni...serialization/
- 04-20-2011, 06:45 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
Thanks for the quick reply!
As the link explains, I can backup the objects through serialization if I explicitly pass the name of the object.
But here I am more interested in backing up the data of fields of the class without needing to refer any name. So that in future, if I need to add or remove array lists or change the name of class, I need not to change the code of the method 'backItUp()'
- 04-20-2011, 09:19 PM #4
Senior Member
- Join Date
- Aug 2010
- Posts
- 127
- Rep Power
- 0
My gues would be to write all the data as a string and then write the string as a txt file.
-
- 04-22-2011, 10:59 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
NIC is the class in which all the arraylists and the method backItUp is present. I want to write backItUp() in such a way that it will automatically search for all the fields the class NIC contains.(In the example I have given above, after searching it should have references for all the array lists.) After that the method should traverse all the array lists and then save the contents into a file.
In simple words, I want create a method which will take back up of all the fields of class in which the method resides.
- 04-23-2011, 01:54 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Package access for class
By jomypgeorge in forum New To JavaReplies: 22Last Post: 12-01-2010, 06:46 AM -
Access an array from a different class
By chief100 in forum New To JavaReplies: 5Last Post: 11-02-2010, 07:57 AM -
why i cant access a method in a sub class?
By javanew in forum New To JavaReplies: 7Last Post: 05-03-2010, 06:29 PM -
Problem to access data when a class calls another class
By ea09530 in forum New To JavaReplies: 0Last Post: 04-04-2010, 10:06 AM -
Access LinkedList from another class
By jboy in forum New To JavaReplies: 20Last Post: 09-12-2009, 08:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks