All,
Considering my earlier query Stackoverflow-Post, here is what I am currently doing. This is a kind of flowchart:
1 > Add record to file:
a. Get the details for new record
b. Retrieve all the records from the file.
c. Compare each record retrieved with the new record details. If match found, do not add to the file, else add the new record.
2 > Search for a record in file.
a. Get the details for the record to be searched (Here only the credit card number.)
b. Retrieve all the records from the file.
c. Compare each record retrieved with the record searched for. If match found, display the details.
3 > Delete a record from the file.
a. Get the details for the record to be deleted (Here only the credit card number.)
b. Retrieve all the records from the file.
c. Compare each record retrieved with the record searched for. If match found, delete the entry from the file.
As can be seen, I am doing an IO every time for a operation. Is there any way I can optimize or improve performance for my code?
The API I am using for Add record is FileWriter
, for search operation it is BufferedReader
and for deleting a record is BufferedReader
and PrintWriter