bra*_*n56 8 java arrays floating-point byte
所以我在这里要做的是获取a float[]
,将其转换为byte[]
,通过网络作为数据包发送,然后将其转换回byte[]
接收终端.
现在我知道我可以通过使用该方法转换float[]
为.但我不知道如何扭转转换.byte[]
getBytes[]
另一种方法...使用ByteArrayOutputStream/DataOutputStream进行输出
float fArr[] = ...;
ByteArrayOutputStream bas = new ByteArrayOutputStream();
DataOutputStream ds = new DataOutputStream(bas);
for (float f : fArr)
ds.writeFloat(f);
byte[] bytes = bas.toByteArray();
Run Code Online (Sandbox Code Playgroud)
使用ByteArrayInputStream/DataInputStream进行输入
byte[] buffer = ...;
ByteArrayInputStream bas = new ByteArrayInputStream(buffer);
DataInputStream ds = new DataInputStream(bas);
float[] fArr = new float[buffer.length / 4]; // 4 bytes per float
for (int i = 0; i < fArr.length; i++)
{
fArr[i] = ds.readFloat();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15409 次 |
最近记录: |