Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read the file content from the Internal storage - Android App

I am a newbie working with Android. A file is already created in the location data/data/myapp/files/hello.txt; the contents of this file is "hello". How do I read the file's content?

like image 777
Shan Avatar asked Feb 08 '13 08:02

Shan


People also ask

How can I see all files in Android app?

On your Android 10 device, open the app drawer and tap the icon for Files. By default, the app displays your most recent files. Swipe down the screen to view all your recent files (Figure A). To see only specific types of files, tap one of the categories at the top, such as Images, Videos, Audio, or Documents.


1 Answers

Take a look this how to use storages in android http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

To read data from internal storage you need your app files folder and read content from here

String yourFilePath = context.getFilesDir() + "/" + "hello.txt"; File yourFile = new File( yourFilePath ); 

Also you can use this approach

FileInputStream fis = context.openFileInput("hello.txt"); InputStreamReader isr = new InputStreamReader(fis); BufferedReader bufferedReader = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) {     sb.append(line); } 
like image 189
Georgy Gobozov Avatar answered Sep 19 '22 11:09

Georgy Gobozov