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

In this chapter you will learn:

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

Description

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

Syntax

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


public StreamReader(
  Stream stream,//from w  w w . jav a  2 s  .  com
  Encoding encoding,
  bool detectEncodingFromByteOrderMarks,
  int bufferSize
)

Parameters

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

  • stream - The stream 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.

Example

The following code example demonstrates this StreamReader constructor.


//from   w  w  w. j  av  a  2  s .  c  o  m
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(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)