Sideway
output.to from Sideway
Draft for Information Only

Content

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

Device I/O

The main components used in .NET framework to access the device i/o are Stream, BufferedStream, FileStream, MemoryStream, StreamReader, StreamWriter, StringReader, StringWriter, TextReader, TextWriter, BinaryReader, and BinaryWriter.

BinaryReader Class

Reads primitive data types as binary values in a specific encoding.

NamespaceSystem.IO AssembliesSystem.IO.dll, mscorlib.dll, netstandard.dll, System.Runtime.Extensions.dll
[System.Runtime.InteropServices.ComVisible(true)]
public class BinaryReader : IDisposable

Inheritance: Object->BinaryReader

Attributes: ComVisibleAttribute

Implements: IDisposable

Constructors

BinaryReader(Stream)

Initializes a new instance of the BinaryReader class based on the specified stream and using UTF-8 encoding.

BinaryReader(Stream, Encoding)

Initializes a new instance of the BinaryReader class based on the specified stream and character encoding.

BinaryReader(Stream, Encoding, Boolean)

Initializes a new instance of the BinaryReader class based on the specified stream and character encoding, and optionally leaves the stream open.

Properties

BaseStream

Exposes access to the underlying stream of the BinaryReader.

Methods

Close()

Closes the current reader and the underlying stream.

Dispose()

Releases all resources used by the current instance of the BinaryReader class.

Dispose(Boolean)

Releases the unmanaged resources used by the BinaryReader class and optionally releases the managed resources.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FillBuffer(Int32)

Fills the internal buffer with the specified number of bytes read from the stream.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
PeekChar()

Returns the next available character and does not advance the byte or character position.

Read()

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.

Read(Byte[], Int32, Int32)

Reads the specified number of bytes from the stream, starting from a specified point in the byte array.

Read(Char[], Int32, Int32)

Reads the specified number of characters from the stream, starting from a specified point in the character array.

Read7BitEncodedInt()

Reads in a 32-bit integer in compressed format.

ReadBoolean()

Reads a Boolean value from the current stream and advances the current position of the stream by one byte.

ReadByte()

Reads the next byte from the current stream and advances the current position of the stream by one byte.

ReadBytes(Int32)

Reads the specified number of bytes from the current stream into a byte array and advances the current position by that number of bytes.

ReadChar()

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.

ReadChars(Int32)

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.

ReadDecimal()

Reads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.

ReadDouble()

Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes.

ReadInt16()

Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes.

ReadInt32()

Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.

ReadInt64()

Reads an 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes.

ReadSByte()

Reads a signed byte from this stream and advances the current position of the stream by one byte.

ReadSingle()

Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.

ReadString()

Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.

ReadUInt16()

Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the position of the stream by two bytes.

ReadUInt32()

Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes.

ReadUInt64()

Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

Remarks

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

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

BinaryWriter Class

Writes primitive types in binary to a stream and supports writing strings in a specific encoding.

NamespaceSystem.IO AssembliesSystem.IO.dll, mscorlib.dll, netstandard.dll, System.Runtime.Extensions.dll
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class BinaryWriter : IDisposable

Inheritance: Object->BinaryWriter

Attributes: ComVisibleAttribute, SerializableAttribute

Implements: IDisposable

Constructors

BinaryWriter()

Initializes a new instance of the BinaryWriter class that writes to a stream.

BinaryWriter(Stream)

Initializes a new instance of the BinaryWriter class based on the specified stream and using UTF-8 encoding.

BinaryWriter(Stream, Encoding)

Initializes a new instance of the BinaryWriter class based on the specified stream and character encoding.

BinaryWriter(Stream, Encoding, Boolean)

Initializes a new instance of the BinaryWriter class based on the specified stream and character encoding, and optionally leaves the stream open.

Fields

Null

Specifies a BinaryWriter with no backing store.

OutStream

Holds the underlying stream.

Properties

BaseStream

Gets the underlying stream of the BinaryWriter.

Methods

Close()

Closes the current BinaryWriter and the underlying stream.

Dispose()

Releases all resources used by the current instance of the BinaryWriter class.

Dispose(Boolean)

Releases the unmanaged resources used by the BinaryWriter and optionally releases the managed resources.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Flush()

Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Seek(Int32, SeekOrigin)

Sets the position within the current stream.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
Write(Boolean)

Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing true.

Write(Byte)

Writes an unsigned byte to the current stream and advances the stream position by one byte.

Write(Byte[])

Writes a byte array to the underlying stream.

Write(Byte[], Int32, Int32)

Writes a region of a byte array to the current stream.

Write(Char)

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.

Write(Char[])

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.

Write(Char[], Int32, Int32)

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.

Write(Decimal)

Writes a decimal value to the current stream and advances the stream position by sixteen bytes.

Write(Double)

Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.

Write(Int16)

Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.

Write(Int32)

Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.

Write(Int64)

Writes an eight-byte signed integer to the current stream and advances the stream position by eight bytes.

Write(SByte)

Writes a signed byte to the current stream and advances the stream position by one byte.

Write(Single)

Writes a four-byte floating-point value to the current stream and advances the stream position by four bytes.

Write(String)

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.

Write(UInt16)

Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.

Write(UInt32)

Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.

Write(UInt64)

Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.

Write7BitEncodedInt(Int32)

Writes a 32-bit integer in a compressed format.

Explicit Interface Implementations

Remarks

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

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

Examples

Examples of BinaryReader and BinaryWriter Classes
ASP.NET Code Input:
<!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>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 200700004 Last Updated: 7/4/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019