C# File ReadLines(String, Encoding)

Description

File ReadLines(String, Encoding) Read the lines of a file that has a specified encoding.

Syntax

File.ReadLines(String, Encoding) has the following syntax.


public static IEnumerable<string> ReadLines(
  string path,
  Encoding encoding
)

Parameters

File.ReadLines(String, Encoding) has the following parameters.

  • path - The file to read.
  • encoding - The encoding that is applied to the contents of the file.

Returns

File.ReadLines(String, Encoding) method returns <

Example


using System.Text;
using System;//from w  w w . j  av a 2  s . c o m
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    foreach (string line in File.ReadLines(@"d:\data\a.txt", Encoding.UTF8))
    {
        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