+ 1
How I can invok a any line that I want from the File?
Suppose if I have file and this file contains information for more than one person how I can invok information about specific person Like 1 2 3 4 I need to call number 3without the Other?
4 ответов
+ 3
ABUBAKAR ALHOMIDY ,
let's assume that the information in each line is like:
1; tom; peters
...
23;...
to get the respective information about the person with the id of 23 we need the following steps
open the file for reading
iterate through the lines of the file and check if the line starts with 23
if yes, use the complete line to process it
close the file
if you want to modify some data and save the changes, we need to do some more effort
happy coding!
+ 3
ABUBAKAR ALHOMIDY ,
to modify data that are stored in a file, the procedure is:
open the file for reading
read all the lines of the file and store them in a data structure line by line
search and modify the related data
write the complete (modified) data structure to a new file (line by line) with a temporary filename
delete the old file and rename the new file to the original name
close file
you should also look for a library, that can do this procedure for you
*** be aware that trying to do this procedures can lead to a file corruption in case of coding errors. so do all your tries only with data that are duplicated ***
+ 1
How I can modify the file without delete previous information?