public class **FileUtil** File I/O utilities.

### Public Methods

|---|---|
| static byte\[\] | [loadByteFromFile](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadByteFromFile(Context,%20java.lang.String))(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath) Loads a binary file from the asset folder. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadLabels](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(Context,%20java.lang.String))(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath) Loads labels from the label file into a list of strings. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadLabels](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(java.io.InputStream))([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream) Loads labels from an input stream of an opened label file. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadLabels](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(java.io.InputStream,%20java.nio.charset.Charset))([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs) Loads labels from an input stream of an opened label file. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadLabels](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(Context,%20java.lang.String,%20java.nio.charset.Charset))(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs) Loads labels from the label file into a list of strings. |
| static [MappedByteBuffer](https://developer.android.com/reference/java/nio/MappedByteBuffer.html) | [loadMappedFile](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadMappedFile(Context,%20java.lang.String))(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath) Loads a file from the asset folder through memory mapping. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadSingleColumnTextFile](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadSingleColumnTextFile(Context,%20java.lang.String,%20java.nio.charset.Charset))(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs) Loads a vocabulary file (a single-column text file) into a list of strings. |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\> | [loadSingleColumnTextFile](https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadSingleColumnTextFile(java.io.InputStream,%20java.nio.charset.Charset))([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs) Loads vocabulary from an input stream of an opened vocabulary file (which is a single-column text file). |

### Inherited Methods

From class java.lang.Object

|---|---|
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

## Public Methods

#### public static byte\[\]
**loadByteFromFile**
(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath)

Loads a binary file from the asset folder.

##### Parameters

| context | Application context to access assets. |
| filePath | Asset path of the file. |
|---|---|

##### Returns

- the byte array for the binary file.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if an I/O error occurs when loading file. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadLabels**
(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath)

Loads labels from the label file into a list of strings.

A legal label file is the plain text file whose contents are split into lines, and each line
is an individual value. The file should be in assets of the context.

<br />

##### Parameters

| context | The context holds assets. |
| filePath | The path of the label file, relative with assets directory. |
|---|---|

##### Returns

- a list of labels.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadLabels**
([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream)

Loads labels from an input stream of an opened label file. See details for label files in
`https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(Context,%20java.lang.String)`.

##### Parameters

| inputStream | the input stream of an opened label file. |
|---|---|

##### Returns

- a list of labels.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadLabels**
([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs)

Loads labels from an input stream of an opened label file. See details for label files in
`https://developers.google.com/edge/api/tflite/java/org/tensorflow/lite/support/common/FileUtil#loadLabels(Context,%20java.lang.String)`.

##### Parameters

| inputStream | the input stream of an opened label file. |
| cs | `Charset` to use when decoding content of label file. |
|---|---|

##### Returns

- a list of labels.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadLabels**
(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs)

Loads labels from the label file into a list of strings.

A legal label file is the plain text file whose contents are split into lines, and each line
is an individual value. The empty lines will be ignored. The file should be in assets of the
context.

<br />

##### Parameters

| context | The context holds assets. |
| filePath | The path of the label file, relative with assets directory. |
| cs | `Charset` to use when decoding content of label file. |
|---|---|

##### Returns

- a list of labels.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|

#### public static [MappedByteBuffer](https://developer.android.com/reference/java/nio/MappedByteBuffer.html)
**loadMappedFile**
(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath)

Loads a file from the asset folder through memory mapping.

##### Parameters

| context | Application context to access assets. |
| filePath | Asset path of the file. |
|---|---|

##### Returns

- the loaded memory mapped file.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if an I/O error occurs when loading the tflite model. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadSingleColumnTextFile**
(Context context, [String](https://developer.android.com/reference/java/lang/String.html) filePath, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs)

Loads a vocabulary file (a single-column text file) into a list of strings.

A vocabulary file is a single-column plain text file whose contents are split into lines,
and each line is an individual value. The file should be in assets of the context.

<br />

##### Parameters

| context | The context holds assets. |
| filePath | The path of the vocabulary file, relative with assets directory. |
| cs |   |
|---|---|

##### Returns

- a list of vocabulary words.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[String](https://developer.android.com/reference/java/lang/String.html)\>
**loadSingleColumnTextFile**
([InputStream](https://developer.android.com/reference/java/io/InputStream.html) inputStream, [Charset](https://developer.android.com/reference/java/nio/charset/Charset.html) cs)

Loads vocabulary from an input stream of an opened vocabulary file (which is a single-column
text file).

A vocabulary file is a single-column plain text file whose contents are split into lines,
and each line is an individual value. The file should be in assets of the context.

<br />

##### Parameters

| inputStream | the input stream of an opened vocabulary file. |
| cs |   |
|---|---|

##### Returns

- a list of vocabulary words.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if error occurs to open or read the file. |
|---|---|