Class

Xojo.IO.TextOutputStream


Warning

This item was deprecated in version 2020r2. Please use TextOutputStream as a replacement.

Description

Used for outputting text of a specific encoding to a file.

Properties

Name

Type

Read-Only

Shared

Delimiter

Text

Encoding

TextEncoding

Methods

Name

Parameters

Returns

Shared

Append

f As FolderItem, encoding As TextEncoding

TextOutputStream

Close

Create

f As FolderItem, encoding As TextEncoding

TextOutputStream

Flush

Handle

type As Xojo.IO.HandleTypes

Ptr

Write

data As String

WriteLine

data As String

Property descriptions


Xojo.IO.TextOutputStream.Delimiter

Delimiter As Text

The character used to mark the end of a line of text written to the file. If this value is not set, the OS default for EndOfLine is used.

Set the delimeter to Tab:

outputStream.Delimiter = &u09

Xojo.IO.TextOutputStream.Encoding

Encoding As TextEncoding

The encoding used for writing the text. Raises an exception if set to Nil.

Change the encoding to ASCII:

Using Xojo.Core
outputStream.Encoding = TextEncoding.ASCII

Method descriptions


Xojo.IO.TextOutputStream.Append

Append(f As FolderItem, encoding As TextEncoding) As TextOutputStream

Opens the passed file so that text can be appended to existing text.

Using Xojo.Core
Using Xojo.IO

Var f As FolderItem
f = SpecialFolder.Documents.Child("SaveData.txt")

Var output As TextOutputStream
Try
  output = TextOutputStream.Append(f, TextEncoding.UTF8)
  output.WriteLine("This text is appended to the end of the file.")
  output.Close
Catch e As IOException
  Label1.Text = "Unable to append to file."
End Try

Xojo.IO.TextOutputStream.Close

Close

Closes the TextOutputStream. The stream is also closed automatically when it goes out of scope.

outputStream.Close

Xojo.IO.TextOutputStream.Create

Create(f As FolderItem, encoding As TextEncoding) As TextOutputStream

Creates a text file for so that text can be written. If the file exists, it will be erased and recreated.

Create a text file and write data to it:

Using Xojo.Core
Using Xojo.IO

Var f As FolderItem
f = SpecialFolder.Documents.Child("SaveData.txt")

Var output As TextOutputStream
Try
  output = TextOutputStream.Create(f, TextEncoding.UTF8)
  output.WriteLine("Hello, World!")
  output.Close
Catch e As IOException
  Label1.Text = "Unable to create or write to file."
End Try

Xojo.IO.TextOutputStream.Flush

Flush

Immediately sends the contents of internal write buffers to disk or to the output stream.

outputStream.Flush

Xojo.IO.TextOutputStream.Handle

Handle(type As Xojo.IO.HandleTypes) As Ptr

Handle returns a handle of the Type passed or -1 if the requested type cannot be retrieved.


Xojo.IO.TextOutputStream.Write

Write(data As String)

Writes the passed data to the output stream.

Var outputText As Text = "This is a test."
outputStream.Write(outputText)

Xojo.IO.TextOutputStream.WriteLine

WriteLine(data As String)

Writes the passed data to the output stream followed by the character(s) defined in Delimiter.

Var outputText As Text = "This is a test."
outputStream.WriteLine("1: " + outputText)
outputStream.WriteLine("2: " + outputText)

Compatibility

All project types on all supported operating systems.

See also

Object parent class; BinaryStream, FolderItem, TextInputStream classes