-
November 21st, 2011, 11:30 PM
#1
[Solved] File question
I need to read the first line in a file then delete that line.
The only way I can think of doing this is reading in the curent file starting at the second line and then over write the file with the new data.
My question is how do I read in the file from the second line into an array to rewrite the file?
Or is there a better easyer way?
Last edited by ron22; November 22nd, 2011 at 11:28 AM.
-
November 22nd, 2011, 12:12 AM
#2
Re: File question
Code:
string path = //Path to the file you want to read/modify
string[] lines = System.IO.File.ReadAllLines(path);
System.IO.StreamWriter w = new System.IO.StreamWriter(path);
for(int i = 1; i < lines.length; i++)
{
w.WriteLine(lines[i]);
}
w.Close();
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
November 22nd, 2011, 11:28 AM
#3
Re: File question
Thanks I knew it was easy it was late and I was not thinking the best.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|