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

# StringReader

` public class StringReader `   
` ` ` extends https://developer.android.com/reference/java/io/Reader ` ` `

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

<br />

*** ** * ** ***

A character stream whose source is a string.

## Summary

### Inherited fields

From class `https://developer.android.com/reference/java/io/Reader` ` 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.

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/StringReader#StringReader(java.lang.String)(https://developer.android.com/reference/java/lang/String s) ` Creates a new string reader. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/io/StringReader#close()() ` Closes the stream and releases any system resources associated with it. |
| ` void` | ` https://developer.android.com/reference/java/io/StringReader#mark(int)(int readAheadLimit) ` Marks the present position in the stream. |
| ` boolean` | ` https://developer.android.com/reference/java/io/StringReader#markSupported()() ` Tells whether this stream supports the mark() operation, which it does. |
| ` int` | ` https://developer.android.com/reference/java/io/StringReader#read()() ` Reads a single character. |
| ` int` | ` https://developer.android.com/reference/java/io/StringReader#read(char[],%20int,%20int)(char[] cbuf, int off, int len) ` Reads characters into a portion of an array. |
| ` boolean` | ` https://developer.android.com/reference/java/io/StringReader#ready()() ` Tells whether this stream is ready to be read. |
| ` void` | ` https://developer.android.com/reference/java/io/StringReader#reset()() ` Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked. |
| ` long` | ` https://developer.android.com/reference/java/io/StringReader#skip(long)(long ns) ` Skips the specified number of characters in the stream. |

### Inherited methods

From class ` https://developer.android.com/reference/java/io/Reader ` ` 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.
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.

## Public constructors

### StringReader

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

```
public StringReader (String s)
```

Creates a new string reader.

<br />

| Parameters ||
|---|---|
| `s` | `String`: String providing the character stream. <br /> |

## Public methods

### close

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

```
public void close ()
```

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously closed stream has no effect. This method will block while there is another thread blocking on the reader.

<br />

### 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 reposition the stream to this point.

<br />

| Parameters ||
|---|---|
| `readAheadLimit` | `int`: Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a string, there is no actual limit, so this argument must not be negative, but is otherwise ignored. <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 `readAheadLimit < 0` |

### 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, which it does.

<br />

| Returns ||
|---|---|
| `boolean` | true if and only if this stream supports the mark operation. <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.

<br />

| Returns ||
|---|---|
| `int` | The character 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 (char[] cbuf, 
                int off, 
                int len)
```

Reads characters into a portion of an array.

<br />

| Parameters ||
|---|---|
| `cbuf` | `char`: Destination buffer <br /> |
| `off` | `int`: Offset at which to start writing 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` |   |

### 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 <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If the stream is closed |

### reset

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

```
public void reset ()
```

Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an 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 ns)
```

Skips the specified number of characters in the stream. Returns the number of characters that were skipped.

The `ns` parameter may be negative, even though the `skip` method of the `https://developer.android.com/reference/java/io/Reader` superclass throws an exception in this case. Negative values of `ns` cause the stream to skip backwards. Negative return values indicate a skip backwards. It is not possible to skip backwards past the beginning of the string.

If the entire string has been read or skipped, then this method has no effect and always returns 0.

<br />

| Parameters ||
|---|---|
| `ns` | `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 |