Given a text file, how can I start reading an arbitrary line and nothing else in the file?
Say I have a test.txt file. How can I read line line 15 in a file?
All I saw was material containing saving the entire text file as an array of String, and then using the line number value as the line number to use from the array ... but there are some difficulties: the text file is incredibly huge, and the machine that I am coding a not entirely accurate system. Speed ββis not a top priority, but it is definitely a serious problem.
Is there a way ONLY to read a specific line of a text file and save the result as a line?
Thank you for your feedback: The KINDA file is structured. He got 25 lines of information and then X lines of numbers, but line 17 of the first 25 has a value of X.
But then there is 1 empty line, and it is repeated as the second record in the file, and X may have a different value for each record.
What I want to do is read and save the first 25 lines as independent values, and then save the next X lines (usually around 250) as an array. Then I am going to store it in the SQL database and repeat with the NEXT record until I get to the Yth record (the number of records in the file is on line 3)
EDIT 2 : Well, I think I came to a solution based on a combination of the answers of your answers.
I will read the first 25 lines and store them as an array. I will copy the corresponding contents of the array to local variables, and then delete the first 25 lines. Then I can use the information to store the next X lines (element value 13 in the array) as an array, serialize it, save it in the database, and then delete the lines I just read.
Then I could repeat the process for each subsequent recording.
Of course, this depends on one assumption that I make that, to be honest, I'm not sure if this is true. Is it possible to delete the first n lines from a text file from C # without having to read the whole thing and overwrite it without the first n lines?