I want to read line by line from file leaving the first line of the file

Recommended Answers

All 4 Replies

I want you to make some attempt at writing the code first.

Two choices, copy the content of the file to an array or convert the content of the file to a stream. You can discard the first line when you process the array or stream

using System;
using System.IO;

class Test 
{

    public static void Main() 
    {
        string path = @"c:\temp\MyTest.txt";
        try 
        {
            if (File.Exists(path)) 
            {
                File.Delete(path);
            }

            using (StreamWriter sw = new StreamWriter(path)) 
            {
                sw.WriteLine("This");
                sw.WriteLine("is some text");
                sw.WriteLine("to test");
                sw.WriteLine("Reading");
            }

            using (StreamReader sr = new StreamReader(path)) 
            {
                while (sr.Peek() >= 0) 
                {
                    Console.WriteLine(sr.ReadLine());
                }
            }
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}

Hope this will help u...
^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.