Regarding File Handling
I made a project in which i am using 2 files
1st file contains the path of the programs
2nd file contains the associated image icon's path
Now when i want to delete a button (which is using both data from the above files)
At that time it is easy to delete the program path from 1st file
But it is difficult for me to delete the icon's path from 2nd file as 2nd file may contain same image icon like others so how can overcome such a problem
Now i want to delete the button that is present in ../b.exe
I can delete it from 1st File
but how should i delete from 2nd file?
Can you provide me a snippet so that it will be easy for me to understand
Thanks in advance
I was going to ask why not have a structured file that allows for both the storage of the file name path and the image icon, such as on the same line, using delimiters, or fixed field delimted, or an XML format?
Or maybe to have a file structured where every odd line is the file path and every even line is the image, so that you woul dhave
and then the operation of reading, and deleting a line is now entirely different, delete lines in pairs right.
or i guess, logically, if you know you want to delete b.exe from the first file, to first determine what line number this is on in the first file, when you delete this line, open the second file, and delete this same line number from the second file.,
where i know i have a previous post somewhere in this forum about how to read a specific line from a file. though in the delete case, i think we might need create a temporary file copy, like to create some temporary file, read every line up to before the line we want to delete into this temporary file, skip the line, and read every line after the line we want to delete, then save the file, and remove the existing file and move the temporary file back to the original file path name.
Yes, that sounds messy to me, it is likely much more optimal to do it using the java.nio.channels.FileChannel, to adjust the contents in the file after the line we want to remove to 'up' in the file. but this API is not line oriented, you would need to compute the bytes in the file offset of the start and end of the line to be deleted.