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?
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.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With