Slow responce from the SD card
I am working on application which will read the text file from the SD card and write its contents to other text file.
The implementation goes like this:
File result = new File("/mnt/sdcard/result.txt");
result .createNewFile();
FileWriter resultFileWriter = new FileWriter(result , true);
File f = new File("/mnt/sdcard/abc.txt");
BufferedReader mainBufferedRead开发者_Go百科er =
new BufferedReader(new FileReader(f));
while((line = mainBufferedReader.readLine() ) != null)
{
lineNo ++
if(lineNo > 50 )
{
resultFileWriter .append(line);
resultFileWriter .append("\n");
resultFileWriter .flush();
}
}
resultFileWriter .close();
resultFileWriter = null;
mainBufferedReader .close();
mainBufferedReader = null;
The above code is working properly , but very few times ( 1 outof 20) it is taking much time do the above operation.
I suspect this is because of slow response from the SD card.
Please suggest me generally when there's chance to slow response from SD card. or please let me know if there's any changes I need to do in my code.
Thanks.
As far as I remember this video is about such kind of delays: http://developer.android.com/videos/index.html#v=c4znvD-7VDA
But the idea is to perform I/O operations asynchronously so these delays won't be able to slow down your UI.
Its better to use SQLITE DB. DB read/write is always faster than File I/O.
精彩评论