Hi, I had a text file in which contains records line by line with ',' as delimiter as I use stringtokenizer and vector to read the data. The format in the text file likes: Name, Sex, Age. I want to add 2 functions: (1) update the record by name, sex or age; (2) delete the whole line of record; Do I need to open a temp text file to do it? And, what is the algorithm can be suggested? For both of them, I want to firstly read the total line numbers. Then, the line number + Name, Sex, Age will be displayed on the console window. User can choose which line of record to update or delete. Or, user can search name in order to do that. But, what is the backend algorithm to handle it? If I have 10 lines of record, I want to delete 7th line, the 7th line of the text file will be blanked. How can I move 8th, 9th and 10th lines of records up by one line in order to fill the blank line? Do I need to copy the first 6 lines to a temp text file and copy the last 3 lines of records to the same temp file first? and then copy all the content of that temp file back to the original text file? If so, how can I copy the same format of the original file (with '\n') to the temp file? I need the same data structure likes Name, Sex, Age. However, when I add records, I need to append the text in the original text file, not override it's current content. Any advice? Thanks Andrew
You should probably do what you just described. I would suggest determining what the field and row delimiters are and then figuring out what the key field(s) is for each row. You could then create your own algorithm. As for determining the number of lines, look at the LineNumberReader class to see if it helps. By the way, this sounds like a class project. So, excuse me if I am not specific with any of my suggestions.