# read

## Description

Reads an existing file in the cache directory of the mobile phone and returns its content.

## Input / Parameter

| Name     | Description                                                                                      | Input Type | Default | Options                   | Required |
| -------- | ------------------------------------------------------------------------------------------------ | ---------- | ------- | ------------------------- | -------- |
| fileName | The name of the file to read.                                                                    | Text       | -       | -                         | Yes      |
| folder   | The folder path of the file. If this input is provided, it will be appended to the storage path. | Text       | -       | -                         | No       |
| dataType | The type of data to return.                                                                      | Text       | -       | Base64, Text, Byte\_Array | Yes      |
| extra    | The stored value that is passed to all the callbacks.                                            | Any        | -       | -                         | No       |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The action performed if this function runs successfully.

| Description                                                       | Output Type |
| ----------------------------------------------------------------- | ----------- |
| Returns the file content based on the user's choice of data type. | Any         |

### errorCallback

The action performed if this function does not run successfully.

| Description               | Output Type |
| ------------------------- | ----------- |
| Returns an error message. | Text        |

## Example

In this example, we will read the file content.

```js
Note: This example will only work after the user has created a file using `File.write` function.
```

### Steps

1. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-7103f5127e84c69f5ff3d0fafed11a3d31aeed98%2Fread-step-1.png?alt=media)
2. Select the event `press` and drag the `File.read` function to the event flow and fill in the parameter.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-cb9f1f4b5fc2c3431ad2c5f03cb9f5ff94aed27e%2Fread-step-2.png?alt=media)

### Result

1. Open the installed app on a device with a debugger on and try to press the button.
2. If the file exists, user should be able to see the content on the console.

   ![](https://github.com/OrangeKloud/emobiq-documentation/blob/master/document/client/006-actions-and-visual-logic/action-reference/react-native/File/read/read-step-3.png)
