-
Read/Write large files
I have been struggling trying to find the best method of reading and writing to large files (>26,000 lines). This is what I am trying to do:
Tester application creates a log file (text based) that has test information in it. These files can get rather large, >2mb a piece. Sometimes the application crashes and need to be fixed. I created an external application that reads a couple of files to get the information I need to repair the log file with. No problem there, takes seconds to do. But the only way I have been able to actually fix the files is to open the log file and line by line write the information to a new file, and when a particular line is equal to what I need to fix I write the new line with the fixed information. Some information that I need to change is at the beginning of the file and some is at the end.
My question is this: Is there anyway to do this without having to go line by line. I would rather just change the needed lines in the beginning with the new information and then skip to a position near the end of the file and edit those lines.
I can use either VB 6.0 or VB .Net.
Thanks!
-
Well, you could use a database rather than a plain .txt file, so you could write the data non-sequentially, then use indexes to put it in the right order when you need it.
If you want to stick with plain .txt, then you could just make every line you write quite long (pad it out with spaces at the end) so there would be room to write in extra data, and extra CR's if you want to break the line into more than one.
These long lines may confuse some text editors (or make the page look wide), so you might want to write nulls instead.
Is that what you mean, or am I missing the point here?
-
Acutally I am not in the position to create the information in a db. The application creates log files for the test that has complete that contains all this information. I cannot play with the format as well. So what I really want to do is to be able to open the file as read/write and then read line by line until I reached the information I need. I then compare that line string with information that it should be and if they are different I want to replace the line string with the new information.
There is a new IO system in VS .Net that allows read/write operations but I have not been able to find the solution.
Thanks for the reply.:D