---
# System prepended metadata

title: 'Android: Read .txt files'
tags: [Android, assets folder, txt files]

---

# Android: Read .txt files 
###### tags: `Android` `txt files` `assets folder`

[TOC]

## Step 1: Android Manifest
Allow writing and reading from our external storage. 
```java=
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
```

## Step 2: Where do we save the .txt files?
It is saved in assets folder.

**How to new an asset folder?**
New -> Folder -> Assets Folder
![](https://i.imgur.com/SYIWk1P.png =400x230)

When you are done with above steps, you will see the assets folder on your left.
![](https://i.imgur.com/jdOBnfl.png =200x165)

## Step 3: Read File
**Note:**
* Remember to close the bufferedReader no matter whether you read it or not.
* getAssets().open(FILE_NAME): Gets the file from assets folder
```java==
BufferedReader reader;

try {
    this.reader = new BufferedReader(
            new InputStreamReader(getAssets().open(FILE_NAME), "UTF-8"));

    String line;

    reader.ready();
    line = reader.readLine();

} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (reader != null) {
        try {
            reader.close();
        } catch (IOException e) {

        }
    }
}
```
:::warning
The Assets Folder is **READ-ONLY**, as well as its contents.
:::

For some other read/write methods we can see this video below:
https://www.youtube.com/watch?v=x3pyyQbwLko