C# StreamReader StreamReader(String, Encoding, Boolean, Int32)

In this chapter you will learn:

  1. Get to know StreamReader.StreamReader(String, Encoding, Boolean, Int32)
  2. Syntax for StreamReader.StreamReader(String, Encoding, Boolean, Int32)
  3. Parameter for StreamReader.StreamReader(String, Encoding, Boolean, Int32)
  4. Example - StreamReader.StreamReader(String, Encoding, Boolean, Int32)

Description

StreamReader StreamReader(String, Encoding, Boolean, Int32) Initializes a new instance of the StreamReader class for the specified file name, with the specified character encoding, byte order mark detection option, and buffer size.

Syntax

StreamReader.StreamReader(String, Encoding, Boolean, Int32) has the following syntax.


public StreamReader(
  string path,//from   www.j  a  v  a 2 s .  c  o m
  Encoding encoding,
  bool detectEncodingFromByteOrderMarks,
  int bufferSize
)

Parameters

StreamReader.StreamReader(String, Encoding, Boolean, Int32) has the following parameters.

  • path - The complete file path to be read.
  • encoding - The character encoding to use.
  • detectEncodingFromByteOrderMarks - Indicates whether to look for byte order marks at the beginning of the file.
  • bufferSize - The minimum buffer size, in number of 16-bit characters.

Example

The following code example demonstrates this StreamReader constructor.


/*from   w  w w .j av a 2s .  c om*/

using System;
using System.IO;
public class MainClass{
  public static void Main(String[] argv){  
    StreamReader sr = 
        new StreamReader(new FileStream("C:\\Temp\\Test.txt"),
        System.Text.Encoding.ASCII, false, 512);

  }
}

Next chapter...

What you will learn in the next chapter:

  1. Get to know StreamReader.StreamReader(Stream, Encoding, Boolean, Int32, Boolean)
  2. Syntax for StreamReader.StreamReader(Stream, Encoding, Boolean, Int32, Boolean)
  3. Parameter for StreamReader.StreamReader(Stream, Encoding, Boolean, Int32, Boolean)
  4. Example - StreamReader.StreamReader(Stream, Encoding, Boolean, Int32, Boolean)