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/InputStreamReader#inhfields) \| [Ctors](https://developer.android.com/reference/java/io/InputStreamReader#pubctors) \| [Methods](https://developer.android.com/reference/java/io/InputStreamReader#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/io/InputStreamReader#inhmethods)

# InputStreamReader


`
public


class
InputStreamReader
`


`


`

`

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.InputStreamReader |

|---|
| Known direct subclasses [FileReader](https://developer.android.com/reference/java/io/FileReader) |---|---| | [FileReader](https://developer.android.com/reference/java/io/FileReader) | Reads text from character files using a default buffer size. | |

<br />

*** ** * ** ***

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`. The charset that it uses
may be specified by name or may be given explicitly, or the platform's
`https://developer.android.com/reference/java/nio/charset/Charset#defaultCharset()` may be accepted.

Each invocation of one of an InputStreamReader's read() methods may
cause one or more bytes to be read from the underlying byte-input stream.
To enable the efficient conversion of bytes to characters, more bytes may
be read ahead from the underlying stream than are necessary to satisfy the
current read operation.

For top efficiency, consider wrapping an InputStreamReader within a
BufferedReader. For example:

```
 BufferedReader in
   = new BufferedReader(new InputStreamReader(anInputStream));
 
```

<br />

**See also:**

- `https://developer.android.com/reference/java/io/BufferedReader`
- `https://developer.android.com/reference/java/io/InputStream`
- `https://developer.android.com/reference/java/nio/charset/Charset`

## 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/InputStreamReader#InputStreamReader(java.io.InputStream)(https://developer.android.com/reference/java/io/InputStream in) ` Creates an InputStreamReader that uses the `https://developer.android.com/reference/java/nio/charset/Charset#defaultCharset()`. |
| ` https://developer.android.com/reference/java/io/InputStreamReader#InputStreamReader(java.io.InputStream,%20java.lang.String)(https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/lang/String charsetName) ` Creates an InputStreamReader that uses the named charset. |
| ` https://developer.android.com/reference/java/io/InputStreamReader#InputStreamReader(java.io.InputStream,%20java.nio.charset.Charset)(https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/nio/charset/Charset cs) ` Creates an InputStreamReader that uses the given charset. |
| ` https://developer.android.com/reference/java/io/InputStreamReader#InputStreamReader(java.io.InputStream,%20java.nio.charset.CharsetDecoder)(https://developer.android.com/reference/java/io/InputStream in, https://developer.android.com/reference/java/nio/charset/CharsetDecoder dec) ` Creates an InputStreamReader that uses the given charset decoder. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/io/InputStreamReader#close()() ` Closes the stream and releases any system resources associated with it. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/InputStreamReader#getEncoding()() ` Returns the name of the character encoding being used by this stream. |
| ` int` | ` https://developer.android.com/reference/java/io/InputStreamReader#read()() ` Reads a single character. |
| ` int` | ` https://developer.android.com/reference/java/io/InputStreamReader#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/InputStreamReader#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/InputStreamReader#ready()() ` Tells whether this stream is ready to be read. |

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

### InputStreamReader

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

```
public InputStreamReader (InputStream in)
```

Creates an InputStreamReader that uses the
`https://developer.android.com/reference/java/nio/charset/Charset#defaultCharset()`.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: An InputStream <br /> |

**See also:**

- `https://developer.android.com/reference/java/nio/charset/Charset#defaultCharset()`

### InputStreamReader

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

```
public InputStreamReader (InputStream in, 
                String charsetName)
```

Creates an InputStreamReader that uses the named charset.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: An InputStream <br /> |
| `charsetName` | `String`: The name of a supported `https://developer.android.com/reference/java/nio/charset/Charset` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/UnsupportedEncodingException` | If the named charset is not supported |

### InputStreamReader

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

```
public InputStreamReader (InputStream in, 
                Charset cs)
```

Creates an InputStreamReader that uses the given charset.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: An InputStream <br /> |
| `cs` | `Charset`: A charset <br /> |

### InputStreamReader

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

```
public InputStreamReader (InputStream in, 
                CharsetDecoder dec)
```

Creates an InputStreamReader that uses the given charset decoder.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: An InputStream <br /> |
| `dec` | `CharsetDecoder`: A charset decoder <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(), 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` |   |

### getEncoding

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

```
public String getEncoding ()
```

Returns the name of the character encoding being used by this stream.

If the encoding has an historical name then that name is returned;
otherwise the encoding's canonical name is returned.

If this instance was created with the `https://developer.android.com/reference/java/io/InputStreamReader#InputStreamReader(java.io.InputStream,%20java.lang.String)` constructor then the returned
name, being unique for the encoding, may differ from the name passed to
the constructor. This method will return `null` if the
stream has been closed.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The historical name of this encoding, or `null` if the stream has been closed <br /> |

**See also:**

- `https://developer.android.com/reference/java/nio/charset/Charset`

### 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. 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/lang/IndexOutOfBoundsException` |   |
| `https://developer.android.com/reference/java/io/IOException` |   |

### 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` |   |

### 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. An InputStreamReader is
ready if its input buffer is not empty, or if bytes are available to be
read from the underlying byte stream.

<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 |