Read A File from Internal Storage to String

Article 37 in Android-Java

2020-08-25 04:39:26 from bugfish
Read A File from Internal Storage to String
Android-Java / File Operations
Last Review on: 2021-10-26 18:08:42 | Hits: 288

 Simple Code to read a File in Android (FROM INTERNAL STORAGE) to a String

String readFile(Context context, String filename) throws IOException {
    String ret = "";
    InputStream inStream = context.openFileInput(filename);
    if ( inStream != null ) {
        InputStreamReader inputStreamReader = new InputStreamReader(inStream);
        BufferedReader bufReader = new BufferedReader(inputStreamReader);
        String currentString;
        StringBuilder finalString = new StringBuilder();
        while ( (currentString = bufReader.readLine()) != null ) {
        ret = finalString.toString();
    return ret;
I do not guarantee the reliability of the information given here, the code described on this page is executed at your own risk and in the event of damage or other unforeseeable consequences I am in no way responsible or liable.
Currently 0 Upvotes!
captcha image
System - 2021-01-01 19:30:08
We appreciate comments on our site!

This Website is using Session Cookies for Site Functionality and AWStats.