Object

TextOutputStream Class

In order to write text to a file, you need to create a TextOutputStream object. TextOutputStreams have methods that allow to write to a file and close the file when you are done writing to it.

Properties
Delimiter
Handle
LastErrorCode

Methods
Flush
Write
WriteError
WriteLine

# Notes

They are created by calling the CreateTextFile and AppendToTextFile methods of a FolderItem object. If you need to specify the encoding of the text, call ConvertEncoding prior to writing the file.

# Constructor

Name | Parameters | Description
--- | --- | ---
TextOutputStream | Handle as Integer, Type as Integer | Type is one of the HandleType class constants and Handle is the appropriate handle type specified by the Type parameter. The HandleType class constants are as follows: 1- HandleTypeWin32Handle. A Windows32 OS handle. 2- HandleTypeFilePointer. A file pointer. 3- HandleTypeFileNumber. A file descriptor. 4- HandleTypeMacFileRefNum. A file reference number. 5- HandleTypeMacFileSpecPointer. An FSSpec. For instance, you can use a Declare to open a file with whatever permissions that you wish, and then pass the Handle to a stream object's constructor.

The TextOutputStream class implements the Writeable class interface. If you implement this interface, you must provide the methods with the parameters as specified by the class interface.

For more information about class interfaces and how to implement them, see the section "Class Interfaces" in the User's Guide.

If you need to write the file using a particular encoding, use the ConvertEncoding function to first convert the encoding of the text to the desired encoding before passing the text to the Write or WriteLine methods. Here is an example:

Dim f As FolderItem
Dim t as TextOutputStream
f = GetFolderItem("Sample.txt")
t = f.CreateTextFile
t.Write ConvertEncoding(Editfield1.text, Encodings.WindowsANSI)
t.close

# Example

This example displays the Save As dialog box. A text file is then created and the text properties of three EditFields are written to the new file. Finally the file is closed.

Dim file As FolderItem
Dim fileStream As TextOutputStream
file= GetSaveFolderItem("application/text","My Info")
fileStream=file.CreateTextFile
fileStream.WriteLine namefield.text
fileStream.WriteLine addressfield.text
fileStream.WriteLine phonefield.text
fileStream.Close

# See Also

BinaryStream, FolderItem, TextInputStream classes; ConvertEncoding function; Encodings object; Writeable class interface.