C# File ReadLines(String)

Description

File ReadLines(String) Reads the lines of a file.

Syntax

File.ReadLines(String) has the following syntax.


public static IEnumerable<string> ReadLines(
  string path
)

Parameters

File.ReadLines(String) has the following parameters.

  • path - The file to read.

Returns

File.ReadLines(String) method returns <

Example

The following example reads the lines of a file to find lines that contain specified strings.


//  ww  w . j a v  a2s  . co m
using System;
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    foreach (string line in File.ReadLines(@"d:\data\a.txt"))
    {
        if (line.Contains("java2s.com") & line.Contains("2014"))
        {
            Console.WriteLine(line);
        }
    }

  }
}
    




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter