Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
Other Resources:
How can I insert or delete a line (or record) in the middle of a file?
How can I insert or delete a line (or record) in the middle of a file?
✍: Guest
In general, there is no way to do this. The usual solution is simply to rewrite the file.
When you find yourself needing to insert data into an existing file, here are a few alternatives you can try:
* Rearrange the data file so that you can append the new information at the end.
* Put the information in a second file.
* Leave some blank space (e.g. a line of 80 spaces, or a field like 0000000000) in the file when it is first written, and overwrite it later with the final information
* (This technique is most portable in binary mode; on some systems, overwriting a text file may truncate it.)
* Use a database instead of a flat file.
Instead of actually deleting records, you might consider just marking them as deleted, and having the code which reads the file ignore them. (You could run a separate coalescion program once in a while to rewrite the file, finally discarding the deleted records. Or, if the records are all the same length, you could take the last record and use it to overwrite the record to be deleted, then truncate the file.)
2015-10-05, 948👍, 0💬
Popular Posts:
How many types of validation controls are provided by ASP.NET ? There are six main types of validati...
What Are the Parameter Modes Supported by PL/SQL? - Oracle DBA FAQ - Creating Your Own PL/SQL Proced...
How To Check the Oracle TNS Settings? - Oracle DBA FAQ - ODBC Drivers, DSN Configuration and ASP Con...
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco...
Which one of the following statements is TRUE in regard to overloading the ++ operator? 1 You cannot...