Results 1 to 2 of 2
Thread: Help with object arrays
- 08-04-2011, 01:38 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 6
- Rep Power
- 0
Help with object arrays
Hi, I have managed to gather user input using the java.util.Scanner and during runtime this input is stored in the properties of a class Called customer,
how do I set up an array of customer objects
and then save them to a txt file ( this save location will be changed to a database in future. )
basicly I would like to know how to save multiple customers information in a .txt file, by adding the class(object?) to an array and then saving the array to a .txt file.
and how to read it back to be able to print the contents of the txt file to the commandline.
- 08-04-2011, 04:30 PM #2
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
I would use an ArrayList to store Customer objects
//Something like this. This assumes that you followed convention, and 'customer' is actually 'Customer'
Two options to make the data persistent:Java Code:ArrayList<Customer> yourVariable = new ArrayList<Customer>();
1. Serialize the object and let Java do the heavy lifting for you.
JDK 5.0 Serialization-related APIs & Developer Guides -- from Sun Microsystems
or
2. Create a text file with all the data you will need to recreate the objects. When you read the file you will have to recreate the objects with the data you saved in the file. You will have to think of a structure that you will be able to consistently parse when you save the file.
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)Last edited by yellowledbet; 08-04-2011 at 04:32 PM.
Similar Threads
-
Insert class file as object in a table & read the object from the blob.
By facemeguru in forum New To JavaReplies: 1Last Post: 02-02-2011, 06:11 PM -
Object Orientation - Arrays
By Boysie in forum Jobs DiscussionReplies: 4Last Post: 04-14-2010, 09:32 PM -
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03-23-2010, 01:40 AM -
Object Arrays
By rsvr in forum New To JavaReplies: 9Last Post: 12-05-2009, 11:27 PM -
Stuck with Java Object Orientated Programming - Arrays
By Phalanx in forum New To JavaReplies: 2Last Post: 12-10-2008, 04:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks