Answers for "read a file from assets android"

1

how to read file from assets folder in android

BufferedReader reader = null;
try {
    reader = new BufferedReader(
        new InputStreamReader(getAssets().open("filename.txt"), "UTF-8")); 

    // do reading, usually loop until end of file reading 
    String mLine;
    while ((mLine = reader.readLine()) != null) {
       //process line
       ...
    }
} catch (IOException e) {
    //log the exception
} finally {
    if (reader != null) {
         try {
             reader.close();
         } catch (IOException e) {
             //log the exception
         }
    }
}
Posted by: Guest on April-11-2020

Code answers related to "read a file from assets android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language