StreamWriter Class

Implements a class for writing data to a file.

Example

The following creates a text file and writes two consecutive lines of data to the file (see StreamReader for the read example):

using elsystem.io;

 

var: StreamWriter myFile(null);

 

myFile = StreamWriter.Create("c:\ExistingFolder\myTestFile.txt");

myFile.WriteLine("This text will be written to line 1 of the file.");

myFile.WriteLine("And a date " + elsystem.DateTime.Now.tostring() + " is written to the second line");

myFile.Close();

Namespace: elsystem.io

Properties
  Name Type Description
Public property AutoFlush bool Gets or sets a value indicating whether the StreamWriter will flush its buffer to the underlying file after every call to write to the stream.
Public property Encoding object Gets the character Encoding for the current instance.
Methods

This class uses overload methods.

  Name Description
Public property Close() Closes the StreamWriter object and the underlying file, and releases any system resources associated with the StreamWriter.
Public property Create(path) Initializes a new instance specifying the full path of the file to write.
Public property Create(path,append) Initializes a new instance specifying the full path of the file to write. Setting append to True allows writing to an existing file.
Public property Create(path,append,enc) Initializes a new instance specifying the full path of the file to write. Setting append to True allows writing to an existing file. The enc parameter specifies the character Encoding.
Public property Flush Clears all buffers and causes any buffered data to be written to the underlying file.
Public property Write(bool) Writes the text representation of a boolean value to the file.
Public property Write(string) Writes a string to the file.
Public property Write(double) Writes the text representation of a 4-byte floating-point value to the file.
Public property Write(float) Writes the text representation of an 8-byte floating-point value to the file.
Public property Write(int) Writes the text representation of a 4-byte signed integer to the file.
Public property Write(int64) Writes the text representation of an 8-byte signed integer to the file.
Public property Write(elsystem.Object) Writes the text representation of an object to the file by calling ToString on that object.
Public property Write(string, int, int) Writes a selected string to the file where string is the initial string; int is the starting position of the selected string (zero based) and int is the length of the selection.
Public property Write(string, params elsystem.Object) Writes a string to the file where string is the initial string and params elsystem.Object is a series of objects. The initial string contains object references within {} brackets which are replaced by the referenced object (zero based).
Public property WriteLine Writes a line terminator to the text file.
Public property WriteLine(bool) Writes the text representation of a Boolean followed by a line terminator to the text file.
Public property WriteLine(string) Writes a string followed by a line terminator to the text stream.
Public property WriteLine(double) Writes the text representation of a 8-byte floating-point value followed by a line terminator to the text file.
Public property WriteLine(float) Writes the text representation of a float value followed by a line terminator to the text file.
Public property WriteLine(int) Writes the text representation of a 4-byte signed integer followed by a line terminator to the text file.
Public property WriteLine(int64) Writes the text representation of an 8-byte signed integer followed by a line terminator to the text file.
Public property WriteLine(elsystem.Object) Writes the text representation of an object by calling ToString on this object, followed by a line terminator to the text file.
Public property WriteLine(string, int, int) Writes a selected string to the file followed by a line terminator where string is the initial string; int is the starting position of the selected string (zero based) and int is the length of the selection.
Public property WriteLine(string, params elsystem.Object) Writes a string to the file followed by a line terminator where string is the initial string and params elsystem.Object is a series of objects. The initial string contains object references within {} brackets which are replaced by the referenced object (zero based). See Composite Formatting for more information.
Inheritance Hierarchy

elsystem.Object

elsystem.io.StreamWriter