以下代码可以正常工作,但需要花费太长时间(超过一分钟)才能打开一个小文件.LogCat显示了很多"## ms"中"GC_FOR_MALLOC释放#### objects/######字节"的实例.有什么建议?
File dirPath = new File(Environment.getExternalStorageDirectory(), "MyFolder");
String content = getFile("test.txt");
public String getFile(String file){
String content = "";
try {
File dirPathFile = new File(dirPath, file);
FileInputStream fis = new FileInputStream(dirPathFile);
int c;
while((c = fis.read()) != -1) {
content += (char)c;
}
fis.close();
} catch (Exception e) {
getLog("Error (" + e.toString() + ") with: " + file);
}
return content;
}
Run Code Online (Sandbox Code Playgroud)
更新:
这就是现在的样子:
File dirPath = new File(Environment.getExternalStorageDirectory(), "MyFolder");
String content = getFile("test.txt");
public String …Run Code Online (Sandbox Code Playgroud)