Java File access - Performance considerations -


All,

Keeping my previous question in mind, this is what I currently do I am here. This is a type of flow chart:

1> Add a record to a file :
a. Get details of new records - Recover all records from the b file.
c. Compare each record you get with new record details. If the match is found, do not add to the file or add new record

2> Search for a record in the file .
a Get details of searchable records (credit card numbers here only)
b. Retrieve all records from file.
c. Every record was searched for, which was searched for. If matches are found, show details.

3> Delete a record from the file .
a record get deleted details (here only credit card number.)
b. Retrieve all records from file.
c. Every record was searched for, which was searched for. If the match is found, remove the entry from the file.

As can be seen, I am doing IOO every time for the operation. Is there a way that I can optimize or improve performance for my code?

The API I am using for the record is FileWriter , this is BufferedReader for search operation and BufferedReader < / Code> and PrintWriter

I also suggest that you have a database But if you have to use a file then I can recommend one option. AHashmant value with the credit card number and the key wrapped in an object as the rest of the information. Each time a new record has been added, add information to the pad and serial the data and delete the old file. To delete the records and to do a very easy search for it, because the information is in Hashp, you have to check all The key is that the key exists and another advantage you do not need to worry about the format for writing in the file and then to parse it.

If the number of records is a big problem that might arise that you have to load a large file in memory. One solution is that you can maintain a threshold for the number of records per file and you can take a look with a navigated map (). A limit of credit card numbers can be kept in a fixed file. This key may be the starting limit of the credit card for the lookup and the price file name can be.


Comments