How to read large text files on Android?

1

I would like to know some tips on how to read large files on Android, as an example I give the GTFS (Google Transit) files that most often have 80 MB

I am putting this data on a server (Firebase) with use of Android application utility.

But I'm getting errors when the reading is halfway, ie when the application bursts the memory.

Note: This method I use.

public List<String> readFile(String fileName){

        List<String> text = new ArrayList<>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(
                    new InputStreamReader(context.getAssets().open(fileName)));
            // do reading, usually loop until end of file reading
            String mLine;
            if((mLine = reader.readLine()) != null){
                //text.add(mLine);
                Log.i(TAG, "          head " + mLine);
            }
            while ((mLine = reader.readLine()) != null) {
                text.add(mLine);
                Log.i(TAG, "          line " + mLine);
            }
            Log.i(TAG,"sucess "+fileName);
        } catch (IOException e) {
            Log.i(TAG, "error " + fileName);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    //log the exception
                }
            }
        }
        return text;
    }
    
asked by anonymous 11.09.2016 / 19:56

0 answers