Differences Between Text, Stream, String and Binary Data

Introduction

This article provides an overview of the differences between Text, Stream, String and Binary Data and related classes to stream. You may be confused about the differences between the terms text, stream, string and binary. The terms text and string are often used interchangeably and sometimes you may assume that binary does not include text.
 
Getting Started 
 
Text

The Text data type represents character data stored in a data backing store, such as a text file or a text column. You can read text from a data backing store using the TextReader class and write text to the data backing store using the TextWriter class. 
 
TextReader

The TextReader class is an abstract base class that reads a sequential series of characters. The StringReader, StreamReader and BinaryReader classes all inherit from the TextReader class.
 
TextWriter

The TextWriter class is an abstract class to write a sequential series of characters. The StringWriter, StreamWriter and BinaryWriter classes all inherit from the TextWriter class.
 
Stream

A stream is a conduit for reading bytes from and writing bytes to a data backing store. The .NET Framework provides the StreamReader and StreamWriter class to read and write text to a file.
 
There are the following three types of the Stream class:
  1. FileStream 
  2. MemoryStream
  3. BufferedStream
 The StreamReader and StreamWriter classes are inherited from the TextReader and TextWriter classes. The constructor of the StreamWriter class determines what will happen when you write to the file.
 
String

A string is an array of characters stored in memory. In the  .NET Framework, a string is represented by the System.String class. It is represented as a String in Visual Basic and a string in C#. StringReader and StringWriter classes are used to read and write strings.
 
StringReader & StringWriter

The StringReader class is used to read strings. The StringReader class can extract each line from a long string that contains multiple lines. The StringWriter class stores its information in a StringBuilder. You can use the StringBuilder class to manipulate strings. When a StringWriter object is created, it must be passed an instance of the StringBuilder class to the constructor of the StringBuilder class.
 
Binary
A binary file is a file encoded in a binary format and the data is stored as a series of bytes. Binary files can contain images, sounds, text or compiled code. The BinaryReader and BinaryWriter classes are designed for reading and writing binary.
 
BinaryReader and BinaryWriter

The BinaryReader and BinaryWriter classes are used to read and write data in binary files, respectively. The class reads and writes data types as binary values. These classes are used to read and write binary files that can be shared with applications that process binary data. 
 
The Text, string and binary data all read and write data based on a specific character-encoding configuration. The default encoding configuration is UTF-8 that encodes Unicode characters.
 
Summery

I hope you now understand the differences of text, string, stream and binary data. 

Up Next
    Ebook Download
    View all
    Learn
    View all