First Name: first_name
Last Name: last_name
and so on. Now the first problem comes from the fact that multiple records are stored in the text file, and the program must go to the next record (forwards/backwards) to edit/delete the data. Is there a way to go to the next record from the record format that I made up? Okay, so look at problem1.jpg again. What I want to do is to move from the first dataset (First Name: Justin...Phone: 7373732) to the next one (Julius...83838) and so on for other entries.
Next is the editing/deleting part. I know how to change the data, problem is, I want to update the current data, and from what I know, if I place the append to the PrintWriter function it will add a new entry to the file. If I remove the append argument, PrintWriter will clear the other records and just write the changes that I specified on the textFields. What I want is to change the data that I want to change and leave the others alone. Now for the delete part, I believe (I haven't start this part) that I would just set the values to " ", just plain spaces, so like
Expand|Select|Wrap|Line Numbers
- output.println("First Name: "+fname);
Expand|Select|Wrap|Line Numbers
- output.println("");
Okay so what have I done. For populating the fields I did a dirty way of using the scanner, then using skip to "skip" the strings that I don't need then retrieve the unskipped strings to show on the textFields.
e.g.
Expand|Select|Wrap|Line Numbers
- Scanner s = new Scanner (new FileInputStream("data.txt"));
- s.skip("First Name: ");
- String fname = s.nextLine();
- //edFname is the name of the textField
- edFname.setText(fname);