我想知道(大概)读取存储在 Android SD 卡上的大文件(50MB 到 100MB)需要多少时间。我在 Google Nexus One 上的 Android 2.3.3 上使用以下代码。这会给我一个合理的估计吗?有没有我应该使用的标准方法?此外,使用本机代码会提高我的文件 I/O 性能吗?
谢谢。
public void readFileFromSDCard() throws IOException
{
long start = System.currentTimeMillis();
long size = 0;
File file = new File(OVERLAY_PATH_BASE + "base-ubuntu.vdi");
try {
InputStream in = new FileInputStream(file);
try {
byte[] tmp = new byte[4096];
int l;
while ((l = in.read(tmp)) != -1) {
size = size + 4096;
}
} finally {
in.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
Log.e(LOG_TAG,
"Reading file " + file.getAbsolutePath() + " with " + size + "bytes took " + (end-start) + " ms.");
}