File question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: File question

  1. #1
    Join Date
    Jun 2009
    Posts
    9

    [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 10:28 AM.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    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.

  3. #3
    Join Date
    Jun 2009
    Posts
    9

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center