Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/java/io/Reader#lfields) \| [Protected Ctors](https://developer.android.com/reference/java/io/Reader#proctors) \| [Methods](https://developer.android.com/reference/java/io/Reader#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/io/Reader#inhmethods)

# Reader

` public abstract class Reader `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Closeable, https://developer.android.com/reference/java/lang/Readable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.io.Reader |

Known direct subclasses [BufferedReader](https://developer.android.com/reference/java/io/BufferedReader), [CharArrayReader](https://developer.android.com/reference/java/io/CharArrayReader), [FilterReader](https://developer.android.com/reference/java/io/FilterReader), [InputStreamReader](https://developer.android.com/reference/java/io/InputStreamReader), [PipedReader](https://developer.android.com/reference/java/io/PipedReader), [StringReader](https://developer.android.com/reference/java/io/StringReader) [BufferedReader](https://developer.android.com/reference/java/io/BufferedReader) Reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. [CharArrayReader](https://developer.android.com/reference/java/io/CharArrayReader) This class implements a character buffer that can be used as a character-input stream. [FilterReader](https://developer.android.com/reference/java/io/FilterReader) Abstract class for reading filtered character streams. [InputStreamReader](https://developer.android.com/reference/java/io/InputStreamReader) An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified `https://developer.android.com/reference/java/nio/charset/Charset`. [PipedReader](https://developer.android.com/reference/java/io/PipedReader) Piped character-input streams. [StringReader](https://developer.android.com/reference/java/io/StringReader) A character stream whose source is a string. Known indirect subclasses [FileReader](https://developer.android.com/reference/java/io/FileReader), [LineNumberReader](https://developer.android.com/reference/java/io/LineNumberReader), [PushbackReader](https://developer.android.com/reference/java/io/PushbackReader) [FileReader](https://developer.android.com/reference/java/io/FileReader) Reads text from character files using a default buffer size. [LineNumberReader](https://developer.android.com/reference/java/io/LineNumberReader) A buffered character-input stream that keeps track of line numbers. [PushbackReader](https://developer.android.com/reference/java/io/PushbackReader) A character-stream reader that allows characters to be pushed back into the stream.   

*** ** * ** ***

Abstract class for reading character streams. The only methods that a subclass must implement are read(char\[\], int, int) and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.
**See also:**

- `https://developer.android.com/reference/java/io/BufferedReader`
- `https://developer.android.com/reference/java/io/LineNumberReader`
- `https://developer.android.com/reference/java/io/CharArrayReader`
- `https://developer.android.com/reference/java/io/InputStreamReader`
- `https://developer.android.com/reference/java/io/FileReader`
- `https://developer.android.com/reference/java/io/FilterReader`
- `https://developer.android.com/reference/java/io/PushbackReader`
- `https://developer.android.com/reference/java/io/PipedReader`
- `https://developer.android.com/reference/java/io/StringReader`
- `https://developer.android.com/reference/java/io/Writer`

## Summary

| ### Fields ||
|---|---|
| ` protected https://developer.android.com/reference/java/lang/Object` | `https://developer.android.com/reference/java/io/Reader#lock` The object used to synchronize operations on this stream. |

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/Reader#Reader()() ` Creates a new character-stream reader whose critical sections will synchronize on the reader itself. |
| ` https://developer.android.com/reference/java/io/Reader#Reader(java.lang.Object)(https://developer.android.com/reference/java/lang/Object lock) ` Creates a new character-stream reader whose critical sections will synchronize on the given object. |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/java/io/Reader#close()() ` Closes the stream and releases any system resources associated with it. |
| ` void` | ` https://developer.android.com/reference/java/io/Reader#mark(int)(int readAheadLimit) ` Marks the present position in the stream. |
| ` boolean` | ` https://developer.android.com/reference/java/io/Reader#markSupported()() ` Tells whether this stream supports the mark() operation. |
| ` static https://developer.android.com/reference/java/io/Reader` | ` https://developer.android.com/reference/java/io/Reader#nullReader()() ` Returns a new `Reader` that reads no characters. |
| ` int` | ` https://developer.android.com/reference/java/io/Reader#read()() ` Reads a single character. |
| ` abstract int` | ` https://developer.android.com/reference/java/io/Reader#read(char[],%20int,%20int)(char[] cbuf, int off, int len) ` Reads characters into a portion of an array. |
| ` int` | ` https://developer.android.com/reference/java/io/Reader#read(char[])(char[] cbuf) ` Reads characters into an array. |
| ` int` | ` https://developer.android.com/reference/java/io/Reader#read(java.nio.CharBuffer)(https://developer.android.com/reference/java/nio/CharBuffer target) ` Attempts to read characters into the specified character buffer. |
| ` boolean` | ` https://developer.android.com/reference/java/io/Reader#ready()() ` Tells whether this stream is ready to be read. |
| ` void` | ` https://developer.android.com/reference/java/io/Reader#reset()() ` Resets the stream. |
| ` long` | ` https://developer.android.com/reference/java/io/Reader#skip(long)(long n) ` Skips characters. |
| ` long` | ` https://developer.android.com/reference/java/io/Reader#transferTo(java.io.Writer)(https://developer.android.com/reference/java/io/Writer out) ` Reads all characters from this reader and writes the characters to the given writer in the order that they are read. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/java/lang/Readable ` ` abstract int` ` https://developer.android.com/reference/java/lang/Readable#read(java.nio.CharBuffer)(https://developer.android.com/reference/java/nio/CharBuffer cb) `

Attempts to read characters into the specified character buffer.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Fields

### lock

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Object lock
```

The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than `this` or a synchronized method.

<br />

## Protected constructors

### Reader

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Reader ()
```

Creates a new character-stream reader whose critical sections will synchronize on the reader itself.

<br />

### Reader

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Reader (Object lock)
```

Creates a new character-stream reader whose critical sections will synchronize on the given object.

<br />

| Parameters ||
|---|---|
| `lock` | `Object`: The Object to synchronize on. <br /> |

## Public methods

### close

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract void close ()
```

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |

### mark

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void mark (int readAheadLimit)
```

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

<br />

| Parameters ||
|---|---|
| `readAheadLimit` | `int`: Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If the stream does not support mark(), or if some other I/O error occurs |

### markSupported

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean markSupported ()
```

Tells whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method.

<br />

| Returns ||
|---|---|
| `boolean` | true if and only if this stream supports the mark operation. <br /> |

### nullReader

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Reader nullReader ()
```

Returns a new `Reader` that reads no characters. The returned stream is initially open. The stream is closed by calling the `close()` method. Subsequent calls to `close()` have no effect.

While the stream is open, the `read()`, `read(char[])`, `read(char[], int, int)`, `read(Charbuffer)`, `ready()`, `skip(long)`, and `transferTo()` methods all behave as if end of stream has been reached. After the stream has been closed, these methods all throw `IOException`.

The `markSupported()` method returns `false`. The `mark()` and `reset()` methods throw an `IOException`.

The `https://developer.android.com/reference/java/io/Reader#lock` used to synchronize operations on the returned `Reader` is not specified.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/io/Reader` | a `Reader` which reads no characters <br /> |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int read ()
```

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

<br />

| Returns ||
|---|---|
| `int` | The character read, as an integer in the range 0 to 65535 (`0x00-0xffff`), or -1 if the end of the stream has been reached <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract int read (char[] cbuf, 
                int off, 
                int len)
```

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

<br />

| Parameters ||
|---|---|
| `cbuf` | `char`: Destination buffer <br /> |
| `off` | `int`: Offset at which to start storing characters <br /> |
| `len` | `int`: Maximum number of characters to read <br /> |

| Returns ||
|---|---|
| `int` | The number of characters read, or -1 if the end of the stream has been reached <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | If `off` is negative, or `len` is negative, or `len` is greater than `cbuf.length - off` |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int read (char[] cbuf)
```

Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

<br />

| Parameters ||
|---|---|
| `cbuf` | `char`: Destination buffer <br /> |

| Returns ||
|---|---|
| `int` | The number of characters read, or -1 if the end of the stream has been reached <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |

### read

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int read (CharBuffer target)
```

Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.

<br />

| Parameters ||
|---|---|
| `target` | `CharBuffer`: the buffer to read characters into <br /> |

| Returns ||
|---|---|
| `int` | The number of characters added to the buffer, or -1 if this source of characters is at its end <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if target is null |
| `https://developer.android.com/reference/java/nio/ReadOnlyBufferException` | if target is a read only buffer |

### ready

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean ready ()
```

Tells whether this stream is ready to be read.

<br />

| Returns ||
|---|---|
| `boolean` | True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |

### reset

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void reset ()
```

Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(), or if some other I/O error occurs |

### skip

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long skip (long n)
```

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.

<br />

| Parameters ||
|---|---|
| `n` | `long`: The number of characters to skip <br /> |

| Returns ||
|---|---|
| `long` | The number of characters actually skipped <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error occurs |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If `n` is negative. |

### transferTo

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long transferTo (Writer out)
```

Reads all characters from this reader and writes the characters to the given writer in the order that they are read. On return, this reader will be at end of the stream. This method does not close either reader or writer.

This method may block indefinitely reading from the reader, or writing to the writer. The behavior for the case where the reader and/or writer is *asynchronously closed*, or the thread interrupted during the transfer, is highly reader and writer specific, and therefore not specified.

If an I/O error occurs reading from the reader or writing to the writer, then it may do so after some characters have been read or written. Consequently the reader may not be at end of the stream and one, or both, streams may be in an inconsistent state. It is strongly recommended that both streams be promptly closed if an I/O error occurs.

<br />

| Parameters ||
|---|---|
| `out` | `Writer`: the writer, non-null <br /> |

| Returns ||
|---|---|
| `long` | the number of characters transferred <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs when reading or writing |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `out` is `null` |