小编Mr.*_*cky的帖子

打开一个12kb的文本文件需要花费太长时间......?

以下代码可以正常工作,但需要花费太长时间(超过一分钟)才能打开一个小文件.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)

android sd-card fileinputstream

3
推荐指数
1
解决办法
473
查看次数

标签 统计

android ×1

fileinputstream ×1

sd-card ×1