Read A File from Internal Storage to String

ID - _BUGFISH - E#37
^Top
<< Back
Mobile-Menu










Read A File from Internal Storage to String
Category: Android-Java
Sub-Category:
Creator: Jan-Maurice Dahlmanns
Created: 2020-08-25 04:39:26
Modified: 2024-11-19 02:28:55
Views: 659

Caution: 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.

 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 ) {
            finalString.append("\n").append(currentString);
        }
        inStream.close();
        ret = finalString.toString();
    }
    return ret;
}
Currently 0 Upvotes!

captcha image
System - 2024-11-05 18:26:46
Commenting System Initialized! Have a very nice day!

Switches: 0 | Arrivals: 7 | Visits: 7
This Website is using Session Cookies for Site Functionality.