jeudi 5 novembre 2015

android read text file so slow

I'm programming an android application. In my application I use FileInputStream to read a text file, which is less than 100 kb in size, and showing its content in the application. The main problem is that although the file is not so big it takes around 3-4 seconds for my device to open the file. Considering the fact the my device has 1gb ram and a four-core CPU I want to know what's wrong with the way I read the text file and is there any better way to make the process faster???

String aBuffer = "";
    try {
        File myFile = new File(input);
        FileInputStream fIn = new FileInputStream(myFile);
        BufferedReader myReader = new BufferedReader(new InputStreamReader(
                fIn));
        String aDataRow = "";

        while ((aDataRow = myReader.readLine()) != null) {
            aBuffer += aDataRow + "\n";
        }
        // Toast.makeText(getBaseContext(), aBuffer,
        // Toast.LENGTH_SHORT).show();
        myReader.close();
    } catch (Exception e) {
        Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT)
                .show();
    }

    return aBuffer;

Aucun commentaire:

Enregistrer un commentaire