<div class="meta" robots="noindex">

</div>

Class

# Xojo.IO.TextInputStream

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `TextInputStream</api/files/textinputstream>` as a replacement.

</div>

## Description

Used to read text of a specific encoding from a file.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                 | Type                                                 | Read-Only | Shared |
|------------------------------------------------------|------------------------------------------------------|-----------|--------|
| `BytePosition<xojo.io.textinputstream.byteposition>` | `UInt64</api/data_types/additional_types/uint64>`    |           |        |
| `Encoding<xojo.io.textinputstream.encoding>`         | `TextEncoding</api/text/encoding_text/textencoding>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                | Parameters                                                                                                                                           | Returns                                       | Shared |
|-----------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|--------|
| `Close<xojo.io.textinputstream.close>`              |                                                                                                                                                      |                                               |        |
| `Constructor<xojo.io.textinputstream.constructor0>` | handle As `Ptr</api/data_types/additional_types/ptr>`, type As Xojo.IO.HandleTypes, encoding As `TextEncoding</api/text/encoding_text/textencoding>` |                                               |        |
| `EOF<xojo.io.textinputstream.eof>`                  |                                                                                                                                                      | `Boolean</api/data_types/boolean>`            |        |
| `Handle<xojo.io.textinputstream.handle>`            | type As Xojo.IO.HandleTypes                                                                                                                          | `Ptr</api/data_types/additional_types/ptr>`   |        |
| `Open<xojo.io.textinputstream.open>`                | file As `FolderItem</api/files/folderitem>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>`                                        | `TextInputStream</api/files/textinputstream>` |        |
| `Read<xojo.io.textinputstream.read>`                | numberOfBytes As `UInt64</api/data_types/additional_types/uint64>`                                                                                   | `String</api/data_types/string>`              |        |
| `ReadAll<xojo.io.textinputstream.readall>`          |                                                                                                                                                      | `String</api/data_types/string>`              |        |
| `ReadLine<xojo.io.textinputstream.readline>`        |                                                                                                                                                      | `String</api/data_types/string>`              |        |

## Property descriptions

<div id="xojo.io.textinputstream.byteposition">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.BytePosition

**BytePosition** As `UInt64</api/data_types/additional_types/uint64>`

Gets or sets the byte position of the file pointer, not the character position. The first position is numbered zero.

<div id="xojo.io.textinputstream.encoding">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Encoding

**Encoding** As `TextEncoding</api/text/encoding_text/textencoding>`

Gets or sets the default encoding for the Read, ReadAll and ReadLine methods.

``` xojo
Using Xojo.Core
inputStream.Encoding = TextEncoding.ASCII
```

## Method descriptions

<div id="xojo.io.textinputstream.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Close

**Close**

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

``` xojo
inputStream.Close
```

<div id="xojo.io.textinputstream.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Constructor

**Constructor**(handle As `Ptr</api/data_types/additional_types/ptr>`, type As Xojo.IO.HandleTypes, encoding As `TextEncoding</api/text/encoding_text/textencoding>`)

<div class="note">

<div class="title">

Note

</div>

`Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.

</div>

Creates a new TextInputStream based on the handle that was passed.

<div id="xojo.io.textinputstream.eof">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.EOF

**EOF** As `Boolean</api/data_types/boolean>`

Returns True when a Read or ReadLine method reaches the end of the text stream.

``` xojo
Var line As Text
While Not inputStream.EOF
  line = inputStream.ReadLine
Wend
```

<div id="xojo.io.textinputstream.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Handle

**Handle**(type As Xojo.IO.HandleTypes) As `Ptr</api/data_types/additional_types/ptr>`

Returns a handle to the stream for use by OS API calls.

<div id="xojo.io.textinputstream.open">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Open

**Open**(file As `FolderItem</api/files/folderitem>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>`) As `TextInputStream</api/files/textinputstream>`

Creates a TextInputStream and connects it to the specified file.

Open a file and read all its text:

``` xojo
Using Xojo.Core
Using Xojo.IO

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

If Not f.Exists Then
  ' Cannot read the file if it does not exist
  Return
End If

Var errorText As Text
Try
  Var input As TextInputStream
  input = TextInputStream.Open(f, TextEncoding.UTF8)
  TextFileArea.Value = input.ReadAll
  input.Close
Catch e As IOException
  errorText = "File IO Error: " + e.Reason
End Try
```

<div id="xojo.io.textinputstream.read">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.Read

**Read**(numberOfBytes As `UInt64</api/data_types/additional_types/uint64>`) As `String</api/data_types/string>`

Reads the specified number of bytes from the stream and returns them as a Text object.

<div id="xojo.io.textinputstream.readall">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.ReadAll

**ReadAll** As `String</api/data_types/string>`

Reads all remaining bytes from the stream and returns them as a Text object.

``` xojo
Var allText As Text
allText = inputStream.ReadAll
```

<div id="xojo.io.textinputstream.readline">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Xojo.IO.TextInputStream.ReadLine

**ReadLine** As `String</api/data_types/string>`

Reads bytes from the stream until an EOL character is encountered and returns them as a Text object.

Load each line of the text file into an array:

``` xojo
Using Xojo.Core
Using Xojo.IO

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

If Not f.Exists Then
  ' Cannot read the file if it does not exist
  Return
End If

Var errorText As Text
Var lines() As Text
Try
  Var input As TextInputStream
  input = TextInputStream.Open(f, TextEncoding.UTF8)
  While Not input.EOF
    lines.AddRow(input.ReadLine)
  Wend
  input.Close
Catch e As IOException
  errorText = "File IO Error: " + e.Reason
End Try
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `BinaryStream</api/files/binarystream>`, `FolderItem</api/files/folderitem>`, `TextOutputStream</api/files/textoutputstream>` classes
