從內部手機存儲中讀取一個小文件(138 kb)非常緩慢。大約需要490毫秒。寫入相同的文件僅在70 ms中完成。 (在仿真器中測得)緩慢讀取文件
有沒有加速的建議?
謝謝,亞歷山大Miehlke,柏林
private String readFromInternal(String filename) {
try {
FileInputStream fileInputStream = openFileInput(filename);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null)
stringBuilder.append(line);
return stringBuilder.toString();
} catch (Exception e) {
return null;
}
}
private boolean writeToInternal(String filename, String text) {
try {
FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
return true;
} catch (Exception e) {
return false;
}
}
令人懷疑。他正在使用BufferedReader。如果緩衝區足夠大,那應該沒什麼區別。 –