1、利用java传递字节流
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
/**
* Created by wikid on 2015/10/26.
*/
public class Test1 {
public static void main(String args[]) throws Exception{
ByteBuffer bb = ByteBuffer.allocate(12);
float arr[] = {1, 2, 3};
bb.asFloatBuffer().put(arr);
FileOutputStream fos = new FileOutputStream("tmp/t0.bin");
fos.write(bb.array());
fos.close();
}
}
2、前端解析
var xhr1 = new XMLHttpRequest();
xhr1.open('GET', 't0.bin', true);
xhr1.responseType = 'arraybuffer';
xhr1.onload = function(e) {
if (this.status == 200) {
var farr = new Float32Array(this.response);
console.log(farr[0]);
}
};
xhr1.send();