I can read the file correctly but it seems that the program is creating a new object everytime it's reading the data into the linkedList instead of adding it into the linkedlist. I'm not quite sure what is happening with my code. Can anyone please tell me what is missing/ what i did wrong. I would really appreciate any help.
//=================================================== //Sample code for reading file
/* This class is used to load the file in from the user */
{ public Keyboard kb = new Keyboard();
public String getFileName(int message) { /* Method: getFileName Description: This function gets the file name Pre-condition: Post-condition: Returns the file name entered by the user. */
Output output = new Output();
output.clearScreen(); if (message == 2) System.out.println("\t\t\t\t" + "Load Attendee File");
// put gap under heading for(int i=0; i<20; i++) System.out.println();
if (message == 2) System.out.println(); String fileName = kb.getLine(" Please enter the attendees file name in the following" + "\n" + "drive letter:\\filename.extension : ");
System.out.print(fileName); //USE TO CHECK IF IT READs THE FILENAME
fileName = fileName.trim();
if (fileName.length() <= 0) { System.out.println("\n\n WARNING: Since no file has been entered the program" + " will now exit "); System.exit(0); } // if
return fileName;
} // getFileName
public AttendeesInfo loadAttendeeFile (String fileName) { /* Method: loadAttendeeFile Description: This function loads the file named fileName into the computers memory Pre-condition: Post-condition: Data is loaded into memory if file exists */
AttendeesInfo attInfo = new AttendeesInfo(); LinkedList list = new LinkedList();
try { File file = new File(fileName); if( file.exists() ) { FileReader filedr = new FileReader ( file ); BufferedReader inFile = new BufferedReader ( filedr );
// Declare variables to hold data from file
String attName, attAddress, line; int attId, listSize; listSize = 0;
//================================================== //Here is my attendee's info class part of the code
AttendeesInfo () { /* Method: AttendeesInfo Description: This is constructor for AttendeesInfo class Pre-condition: Post-condition: Private variables are initialized */