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

# DataInputStream


`
public


class
DataInputStream
`


`


`

`


`

`

extends https://developer.android.com/reference/java/io/FilterInputStream


`

`


implements

https://developer.android.com/reference/java/io/DataInput


`

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

<br />

*** ** * ** ***

A data input stream lets an application read primitive Java data
types from an underlying input stream in a machine-independent
way. An application uses a data output stream to write data that
can later be read by a data input stream.


DataInputStream is not necessarily safe for multithreaded access.
Thread safety is optional and is the responsibility of users of
methods in this class.
**See also:**

- `https://developer.android.com/reference/java/io/DataOutputStream`

## Summary

| ### Inherited fields |
|---|
| From class `https://developer.android.com/reference/java/io/FilterInputStream` |---|---| | ` protected https://developer.android.com/reference/java/io/InputStream` | `https://developer.android.com/reference/java/io/FilterInputStream#in` The input stream to be filtered. | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/io/DataInputStream#DataInputStream(java.io.InputStream)(https://developer.android.com/reference/java/io/InputStream in) ` Creates a DataInputStream that uses the specified underlying InputStream. |

| ### Public methods ||
|---|---|
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#read(byte[])(byte[] b) ` Reads some number of bytes from the contained input stream and stores them into the buffer array `b`. |
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads up to `len` bytes of data from the contained input stream into an array of bytes. |
| ` final boolean` | ` https://developer.android.com/reference/java/io/DataInputStream#readBoolean()() ` See the general contract of the `readBoolean` method of `DataInput`. |
| ` final byte` | ` https://developer.android.com/reference/java/io/DataInputStream#readByte()() ` See the general contract of the `readByte` method of `DataInput`. |
| ` final char` | ` https://developer.android.com/reference/java/io/DataInputStream#readChar()() ` See the general contract of the `readChar` method of `DataInput`. |
| ` final double` | ` https://developer.android.com/reference/java/io/DataInputStream#readDouble()() ` See the general contract of the `readDouble` method of `DataInput`. |
| ` final float` | ` https://developer.android.com/reference/java/io/DataInputStream#readFloat()() ` See the general contract of the `readFloat` method of `DataInput`. |
| ` final void` | ` https://developer.android.com/reference/java/io/DataInputStream#readFully(byte[])(byte[] b) ` See the general contract of the `readFully` method of `DataInput`. |
| ` final void` | ` https://developer.android.com/reference/java/io/DataInputStream#readFully(byte[],%20int,%20int)(byte[] b, int off, int len) ` See the general contract of the `readFully` method of `DataInput`. |
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#readInt()() ` See the general contract of the `readInt` method of `DataInput`. |
| ` final https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInputStream#readLine()() ` *This method is deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the `BufferedReader.readLine()` method. Programs that use the `DataInputStream` class to read lines can be converted to use the `BufferedReader` class by replacing code of the form:* > ``` >     DataInputStream d = new DataInputStream(in); > ``` *with: > ``` > BufferedReader d > = new BufferedReader(new InputStreamReader(in)); > ```* <br /> |
| ` final long` | ` https://developer.android.com/reference/java/io/DataInputStream#readLong()() ` See the general contract of the `readLong` method of `DataInput`. |
| ` final short` | ` https://developer.android.com/reference/java/io/DataInputStream#readShort()() ` See the general contract of the `readShort` method of `DataInput`. |
| ` final https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInputStream#readUTF()() ` See the general contract of the `readUTF` method of `DataInput`. |
| ` static final https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInputStream#readUTF(java.io.DataInput)(https://developer.android.com/reference/java/io/DataInput in) ` Reads from the stream `in` a representation of a Unicode character string encoded in [modified UTF-8](https://developer.android.com/reference/java/io/DataInput#modified-utf-8) format; this string of characters is then returned as a `String`. |
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#readUnsignedByte()() ` See the general contract of the `readUnsignedByte` method of `DataInput`. |
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#readUnsignedShort()() ` See the general contract of the `readUnsignedShort` method of `DataInput`. |
| ` final int` | ` https://developer.android.com/reference/java/io/DataInputStream#skipBytes(int)(int n) ` See the general contract of the `skipBytes` method of `DataInput`. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/io/FilterInputStream ` |---|---| | ` int` | ` https://developer.android.com/reference/java/io/FilterInputStream#available()() ` Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. | | ` void` | ` https://developer.android.com/reference/java/io/FilterInputStream#close()() ` Closes this input stream and releases any system resources associated with the stream. | | ` void` | ` https://developer.android.com/reference/java/io/FilterInputStream#mark(int)(int readlimit) ` Marks the current position in this input stream. | | ` boolean` | ` https://developer.android.com/reference/java/io/FilterInputStream#markSupported()() ` Tests if this input stream supports the `mark` and `reset` methods. | | ` int` | ` https://developer.android.com/reference/java/io/FilterInputStream#read()() ` Reads the next byte of data from this input stream. | | ` int` | ` https://developer.android.com/reference/java/io/FilterInputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads up to `len` bytes of data from this input stream into an array of bytes. | | ` int` | ` https://developer.android.com/reference/java/io/FilterInputStream#read(byte[])(byte[] b) ` Reads up to `b.length` bytes of data from this input stream into an array of bytes. | | ` void` | ` https://developer.android.com/reference/java/io/FilterInputStream#reset()() ` Repositions this stream to the position at the time the `mark` method was last called on this input stream. | | ` long` | ` https://developer.android.com/reference/java/io/FilterInputStream#skip(long)(long n) ` Skips over and discards `n` bytes of data from the input stream. | ||
| From class ` https://developer.android.com/reference/java/io/InputStream ` |---|---| | ` int` | ` https://developer.android.com/reference/java/io/InputStream#available()() ` Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#close()() ` Closes this input stream and releases any system resources associated with the stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#mark(int)(int readlimit) ` Marks the current position in this input stream. | | ` boolean` | ` https://developer.android.com/reference/java/io/InputStream#markSupported()() ` Tests if this input stream supports the `mark` and `reset` methods. | | ` static https://developer.android.com/reference/java/io/InputStream` | ` https://developer.android.com/reference/java/io/InputStream#nullInputStream()() ` Returns a new `InputStream` that reads no bytes. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#read(byte[])(byte[] b) ` Reads some number of bytes from the input stream and stores them into the buffer array `b`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/InputStream#read()() ` Reads the next byte of data from the input stream. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads up to `len` bytes of data from the input stream into an array of bytes. | | ` byte[]` | ` https://developer.android.com/reference/java/io/InputStream#readAllBytes()() ` Reads all remaining bytes from the input stream. | | ` int` | ` https://developer.android.com/reference/java/io/InputStream#readNBytes(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads the requested number of bytes from the input stream into the given byte array. | | ` byte[]` | ` https://developer.android.com/reference/java/io/InputStream#readNBytes(int)(int len) ` Reads up to a specified number of bytes from the input stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#reset()() ` Repositions this stream to the position at the time the `mark` method was last called on this input stream. | | ` long` | ` https://developer.android.com/reference/java/io/InputStream#skip(long)(long n) ` Skips over and discards `n` bytes of data from this input stream. | | ` void` | ` https://developer.android.com/reference/java/io/InputStream#skipNBytes(long)(long n) ` Skips over and discards exactly `n` bytes of data from this input stream. | | ` long` | ` https://developer.android.com/reference/java/io/InputStream#transferTo(java.io.OutputStream)(https://developer.android.com/reference/java/io/OutputStream out) ` Reads all bytes from this input stream and writes the bytes to the given output stream 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/io/DataInput ` |---|---| | ` abstract boolean` | ` https://developer.android.com/reference/java/io/DataInput#readBoolean()() ` Reads one input byte and returns `true` if that byte is nonzero, `false` if that byte is zero. | | ` abstract byte` | ` https://developer.android.com/reference/java/io/DataInput#readByte()() ` Reads and returns one input byte. | | ` abstract char` | ` https://developer.android.com/reference/java/io/DataInput#readChar()() ` Reads two input bytes and returns a `char` value. | | ` abstract double` | ` https://developer.android.com/reference/java/io/DataInput#readDouble()() ` Reads eight input bytes and returns a `double` value. | | ` abstract float` | ` https://developer.android.com/reference/java/io/DataInput#readFloat()() ` Reads four input bytes and returns a `float` value. | | ` abstract void` | ` https://developer.android.com/reference/java/io/DataInput#readFully(byte[])(byte[] b) ` Reads some bytes from an input stream and stores them into the buffer array `b`. | | ` abstract void` | ` https://developer.android.com/reference/java/io/DataInput#readFully(byte[],%20int,%20int)(byte[] b, int off, int len) ` Reads `len` bytes from an input stream. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readInt()() ` Reads four input bytes and returns an `int` value. | | ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInput#readLine()() ` Reads the next line of text from the input stream. | | ` abstract long` | ` https://developer.android.com/reference/java/io/DataInput#readLong()() ` Reads eight input bytes and returns a `long` value. | | ` abstract short` | ` https://developer.android.com/reference/java/io/DataInput#readShort()() ` Reads two input bytes and returns a `short` value. | | ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/io/DataInput#readUTF()() ` Reads in a string that has been encoded using a [modified UTF-8](https://developer.android.com/reference/java/io/DataInputStream#modified-utf-8) format. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readUnsignedByte()() ` Reads one input byte, zero-extends it to type `int`, and returns the result, which is therefore in the range `0` through `255`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#readUnsignedShort()() ` Reads two input bytes and returns an `int` value in the range `0` through `65535`. | | ` abstract int` | ` https://developer.android.com/reference/java/io/DataInput#skipBytes(int)(int n) ` Makes an attempt to skip over `n` bytes of data from the input stream, discarding the skipped bytes. | ||
| 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

### DataInputStream

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

```
public DataInputStream (InputStream in)
```

Creates a DataInputStream that uses the specified
underlying InputStream.

<br />

| Parameters ||
|---|---|
| `in` | `InputStream`: the specified input stream <br /> |

## Public methods

### read

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

```
public final int read (byte[] b)
```

Reads some number of bytes from the contained input stream and
stores them into the buffer array `b`. The number of
bytes actually read is returned as an integer. This method blocks
until input data is available, end of file is detected, or an
exception is thrown.

If `b` is null, a `NullPointerException` is
thrown. If the length of `b` is zero, then no bytes are
read and `0` is returned; otherwise, there is an attempt
to read at least one byte. If no byte is available because the
stream is at end of file, the value `-1` is returned;
otherwise, at least one byte is read and stored into `b`.

The first byte read is stored into element `b[0]`, the
next one into `b[1]`, and so on. The number of bytes read
is, at most, equal to the length of `b`. Let `k`
be the number of bytes actually read; these bytes will be stored in
elements `b[0]` through `b[k-1]`, leaving
elements `b[k]` through `b[b.length-1]`
unaffected.

The `read(b)` method has the same effect as:
>
> ```
> read(b, 0, b.length)
> ```

<br />

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the buffer into which the data is read. <br /> |

| Returns ||
|---|---|
| `int` | the total number of bytes read into the buffer, or `-1` if there is no more data because the end of the stream has been reached. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the first byte cannot be read for any reason other than end of file, the stream has been closed and the underlying input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`
- `https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int)`

### read

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

```
public final int read (byte[] b, 
                int off, 
                int len)
```

Reads up to `len` bytes of data from the contained
input stream into an array of bytes. An attempt is made to read
as many as `len` bytes, but a smaller number may be read,
possibly zero. The number of bytes actually read is returned as an
integer.

This method blocks until input data is available, end of file is
detected, or an exception is thrown.

If `len` is zero, then no bytes are read and
`0` is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at end of
file, the value `-1` is returned; otherwise, at least one
byte is read and stored into `b`.

The first byte read is stored into element `b[off]`, the
next one into `b[off+1]`, and so on. The number of bytes read
is, at most, equal to `len`. Let *k* be the number of
bytes actually read; these bytes will be stored in elements
`b[off]` through `b[off+`*k*`-1]`,
leaving elements `b[off+`*k*`]` through
`b[off+len-1]` unaffected.

In every case, elements `b[0]` through
`b[off]` and elements `b[off+len]` through
`b[b.length-1]` are unaffected.

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the buffer into which the data is read. <br /> |
| `off` | `int`: the start offset in the destination array `b` <br /> |
| `len` | `int`: the maximum number of bytes read. <br /> |

| Returns ||
|---|---|
| `int` | the total number of bytes read into the buffer, or `-1` if there is no more data because the end of the stream has been reached. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the first byte cannot be read for any reason other than end of file, the stream has been closed and the underlying input stream does not support reading after close, or another I/O error occurs. |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | If `off` is negative, `len` is negative, or `len` is greater than `b.length - off` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | If `b` is `null`. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`
- `https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int)`

### readBoolean

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

```
public final boolean readBoolean ()
```

See the general contract of the `readBoolean`
method of `DataInput`.


Bytes for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `boolean` | the `boolean` value read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream has reached the end. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readByte

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

```
public final byte readByte ()
```

See the general contract of the `readByte`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `byte` | the next byte of this input stream as a signed 8-bit `byte`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream has reached the end. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readChar

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

```
public final char readChar ()
```

See the general contract of the `readChar`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `char` | the next two bytes of this input stream, interpreted as a `char`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading two bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readDouble

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

```
public final double readDouble ()
```

See the general contract of the `readDouble`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `double` | the next eight bytes of this input stream, interpreted as a `double`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading eight bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/DataInputStream#readLong()`
- `https://developer.android.com/reference/java/lang/Double#longBitsToDouble(long)`

### readFloat

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

```
public final float readFloat ()
```

See the general contract of the `readFloat`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `float` | the next four bytes of this input stream, interpreted as a `float`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading four bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/DataInputStream#readInt()`
- `https://developer.android.com/reference/java/lang/Float#intBitsToFloat(int)`

### readFully

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

```
public final void readFully (byte[] b)
```

See the general contract of the `readFully`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the buffer into which the data is read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading all the bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `b` is `null`. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readFully

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

```
public final void readFully (byte[] b, 
                int off, 
                int len)
```

See the general contract of the `readFully`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Parameters ||
|---|---|
| `b` | `byte`: the buffer into which the data is read. <br /> |
| `off` | `int`: the start offset in the data array `b`. <br /> |
| `len` | `int`: the number of bytes to read. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading all the bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if `off` is negative, `len` is negative, or `len` is greater than `b.length - off`. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `b` is `null`. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readInt

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

```
public final int readInt ()
```

See the general contract of the `readInt`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `int` | the next four bytes of this input stream, interpreted as an `int`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading four bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readLine

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

```
public final String readLine ()
```


**This method is deprecated.**   

This method does not properly convert bytes to characters.
As of JDK 1.1, the preferred way to read lines of text is via the
`BufferedReader.readLine()` method. Programs that use the
`DataInputStream` class to read lines can be converted to use
the `BufferedReader` class by replacing code of the form:
>
> ```
>     DataInputStream d = new DataInputStream(in);
> ```
with:
>
> ```
>     BufferedReader d
>          = new BufferedReader(new InputStreamReader(in));
> ```

<br />

See the general contract of the `readLine`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the next line of text from this input stream. <br /> |

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

**See also:**

- `https://developer.android.com/reference/java/io/BufferedReader#readLine()`
- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readLong

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

```
public final long readLong ()
```

See the general contract of the `readLong`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `long` | the next eight bytes of this input stream, interpreted as a `long`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading eight bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readShort

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

```
public final short readShort ()
```

See the general contract of the `readShort`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `short` | the next two bytes of this input stream, interpreted as a signed 16-bit number. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading two bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readUTF

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

```
public final String readUTF ()
```

See the general contract of the `readUTF`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a Unicode string. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading all the bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |
| `https://developer.android.com/reference/java/io/UTFDataFormatException` | if the bytes do not represent a valid modified UTF-8 encoding of a string. |

**See also:**

- `https://developer.android.com/reference/java/io/DataInputStream#readUTF(java.io.DataInput)`

### readUTF

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

```
public static final String readUTF (DataInput in)
```

Reads from the
stream `in` a representation
of a Unicode character string encoded in
[modified UTF-8](https://developer.android.com/reference/java/io/DataInput#modified-utf-8) format;
this string of characters is then returned as a `String`.
The details of the modified UTF-8 representation
are exactly the same as for the `readUTF`
method of `DataInput`.

<br />

| Parameters ||
|---|---|
| `in` | `DataInput`: a data input stream. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a Unicode string. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if the input stream reaches the end before all the bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |
| `https://developer.android.com/reference/java/io/UTFDataFormatException` | if the bytes do not represent a valid modified UTF-8 encoding of a Unicode string. |

**See also:**

- `https://developer.android.com/reference/java/io/DataInputStream#readUnsignedShort()`

### readUnsignedByte

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

```
public final int readUnsignedByte ()
```

See the general contract of the `readUnsignedByte`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `int` | the next byte of this input stream, interpreted as an unsigned 8-bit number. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream has reached the end. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### readUnsignedShort

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

```
public final int readUnsignedShort ()
```

See the general contract of the `readUnsignedShort`
method of `DataInput`.


Bytes
for this operation are read from the contained
input stream.

<br />

| Returns ||
|---|---|
| `int` | the next two bytes of this input stream, interpreted as an unsigned 16-bit integer. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/EOFException` | if this input stream reaches the end before reading two bytes. |
| `https://developer.android.com/reference/java/io/IOException` | the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |

**See also:**

- `https://developer.android.com/reference/java/io/FilterInputStream#in`

### skipBytes

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

```
public final int skipBytes (int n)
```

See the general contract of the `skipBytes`
method of `DataInput`.


Bytes for this operation are read from the contained
input stream.

<br />

| Parameters ||
|---|---|
| `n` | `int`: the number of bytes to be skipped. <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes skipped. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if the contained input stream does not support seek, or the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs. |