CodePudding user response:
Want to how to modify the length variable constant,Actually the problem with no direct relationship to the special language, you'd better find out the operating system's file system, as well as the disk file storage,
CodePudding user response:
So-called modify delete file a certain position, is actually read the open files, a then 'a position before the modification and deletion of content + a + modification and deletion of the contents of the content of the modify delete position after b' save to file, and close the file. A, deleting a file, the file b changed its name to the same as the before file a name, that's it,CodePudding user response:
If change length unchanged after, you can open in binary mode, located directly to the line to be modified, write a line, preservation,, of course, in fact in the disk to save point of view, it may also change the physical address, but this is only a file cache (intuitive see only open a file),
If more general (does not guarantee that the modified governor is unchanged), is the way upstairs:
Open the original file a 1 input mode;
Open new file b 2 output mode;
3, Line by Line Input from a read data, Print write b, until to change the Line;
4 to change the line of the discarded from a read, will be the new content to b;
To simulate in step 3, 5 copies the rest of the line from a to b,
6 close two files
7 delete a, b's file name is changed to the original,
CodePudding user response:
Upstairs, I can give a instance??CodePudding user response:
If often want to change the content, it is suggested that using the INI file format, this feel free to add a line to delete a line, modify, read speed can reach tens of thousands of times per secondCodePudding user response: