The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
StreamReader::CurrentEncoding Property
.NET Framework (current version)
Gets the current character encoding that the current StreamReader object is using.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Text::Encoding^The current character encoding used by the current reader. The value can be different after the first call to any Read method of StreamReader, since encoding autodetection is not done until the first call to a Read method.
For a list of common I/O tasks, see Common I-O Tasks.
The following code example gets the encoding of the specified StreamReader object.
using namespace System; using namespace System::IO; using namespace System::Text; int main() { String^ path = "c:\\temp\\MyTest.txt"; try { if ( File::Exists( path ) ) { File::Delete( path ); } //Use an encoding other than the default (UTF8). StreamWriter^ sw = gcnew StreamWriter( path,false,gcnew UnicodeEncoding ); try { sw->WriteLine( "This" ); sw->WriteLine( "is some text" ); sw->WriteLine( "to test" ); sw->WriteLine( "Reading" ); } finally { delete sw; } StreamReader^ sr = gcnew StreamReader( path,true ); try { while ( sr->Peek() >= 0 ) { Console::Write( (Char)sr->Read() ); } //Test for the encoding after reading, or at least //after the first read. Console::WriteLine( "The encoding used was {0}.", sr->CurrentEncoding ); Console::WriteLine(); } finally { delete sr; } } catch ( Exception^ e ) { Console::WriteLine( "The process failed: {0}", e ); } }
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show: