【发布时间】:2011-10-28 03:52:09
【问题描述】:
我正在将带有 InputStream 的文件读入字节数组,然后将每个字节更改为 int。然后我将 int 存储到另一个数组中。有没有办法让这更有效?具体来说,有没有办法只使用一个数组而不是两个?对于我的程序来说,分配这两个数组花费的时间太长了。
这就是我现在正在做的事情(is 是 InputStream):
byte[] a = new byte[num];
int[] b = new int[num];
try {
is.read(a, 0, num);
for (int j = 0; j < nPixels; j++) {
b[j] = (int) a[j] & 0xFF; //converting from a byte to an "unsigned" int
}
} catch (IOException e) { }
【问题讨论】:
-
我希望你知道 read(byte[] b, int off, int len) 不能保证读取完整的缓冲区。
标签: java android arrays performance