Device I/O BinaryReader Class Constructors Properties Methods Explicit Interface Implementations Remarks Applies to See also BinaryWriter Class Constructors Fields Properties Methods Explicit Interface Implementations Remarks Applies to See also Examples Source/Reference
Reads characters from the underlying stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream.
Reads the next character from the current stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream.
Reads the specified number of characters from the current stream, returns the data in a character array, and advances the current position in accordance with the Encoding used and the specific character being read from the stream.
The BinaryReader class provides methods that simplify reading primitive data types from a stream. For example, you can use the ReadBoolean method to read the next byte as a Boolean value and advance the current position in the stream by one byte. The class includes read methods that support different data types.
When you create a new instance of the BinaryReader class, you provide the stream to read from, and optionally specify the type of encoding and whether to leave the stream open after disposing the BinaryReader object. If you do not specify an encoding type, UTF-8 is used.
Important
This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.
Writes a Unicode character to the current stream and advances the current position of the stream in accordance with the Encoding used and the specific characters being written to the stream.
Writes a character array to the current stream and advances the current position of the stream in accordance with the Encoding used and the specific characters being written to the stream.
Writes a section of a character array to the current stream, and advances the current position of the stream in accordance with the Encoding used and perhaps the specific characters being written to the stream.
Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream.
The BinaryWriter class provides methods that simplify writing primitive data types to a stream. For example, you can use the Write method to write a Boolean value to the stream as a one-byte value. The class includes write methods that support different data types.
When you create a new instance of the BinaryWriter class, you provide the stream to write to, and optionally specify the type of encoding and whether to leave the stream open after disposing the BinaryWriter object. If you do not specify an encoding type, UTF-8 is used.
Important
This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.
A derived class can override the methods of this class to give unique character encodings.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server" >
Sub Page_Load()
Dim xstr As String
Dim xstr1 As String = "abcdefgh"
Dim xpath As String = "T:\filestream\filestream.txt"
If System.IO.Directory.Exists("T:\filestream") Then
System.IO.Directory.Delete("T:\filestream", true)
End If
System.IO.Directory.CreateDirectory("T:\filestream")
xstr = "instantiate a binarywriter of " & xpath & "<br /><br />"
Dim xbwriter As New System.IO.BinaryWriter(System.IO.File.Open(xpath,System.IO.FileMode.Create))
xstr = xstr & "Given string: " & xstr1 & "<br />"
xstr = xstr & "Write the binary of binarywriter to the file." & "<br />"
xbwriter.Write(xstr1)
xbwriter.Flush()
xbwriter.Close()
xstr = xstr & "<br />instantiate a binaryreader of " & xpath & "<br /><br />"
Dim xbreader As New System.IO.BinaryReader(System.IO.File.Open(xpath,System.IO.FileMode.Open))
xstr = xstr & "Read a string from streamreader: " & xbreader.ReadString() & "<br />"
xbreader.Close()
lbl01.Text = xstr
End Sub
</script>
</head>
<body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
<% Response.Write ("<h1>This is a Sample Page of BinaryReader and BinaryWriter Classes</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>