我正在从二进制文件中读取字节,现在我必须获取流的索引位置,我使用的是CountingInputStream类和getByteCount方法,但这个方法返回0。
这是我的代码。
public void readIndex(InputStream iStream)
{
SwappedDataInputStream input;
input = new SwappedDataInputStream(iStream);
int locKey;
int x=0;
int y=0;
try{
setINoOfTiles(input.readInt());
CountingInputStream cis = new CountingInputStream(iStream);
for(int i=0; i<iNoOfTiles; i++)
{
x = input.readInt()/100;
y =input.readInt()/100;
MapTileHeader tTile = new MapTileHeader(x, y, mapType);
locKey = input.readInt();
HashMap<Integer, MapTileHeader> iTileListOffsets = new HashMap<Integer, MapTileHeader>();
iTileListOffsets.put(locKey, tTile);
}
String out = IOUtils.toString(cis);
long count = cis.getByteCount();
Log.i("count", "count =" + count);
}catch(Exception e )
{
e.printStackTrace();
}
}发布于 2010-08-12 19:43:19
使用input = new SwappedDataInputStream(cis);并相应地重新排列声明。
https://stackoverflow.com/questions/3467194
复制相似问题