我遇到FileOutputStream问题。
我使用这个简单的代码:
byte[] data1 = BD25Writer.getData1();
byte[] data2 = BD25Writer.getData2();
FileOutputStream dbf = new FileOutputStream(new File(file.getPath(), "file1.dbf"));
dbf.write(data1);
dbf.close();
FileOutputStream dbt = new FileOutputStream(new File(file.getPath(), "file2.dbt"));
dbt.write(data2);
dbt.close();
在大多数平台(Windows,Android)上正确编写文件。在HEX编辑器中,它看起来像这样:
但是只有一个设备(YotaPhone2,型号:YD201,android 6.0.1),具有相同字节的代码无法正常工作。写入文件的不存在的字节:
方法.getData1()和.getData2()正常工作。这些方法只是将浮点数据写入一个字节数组。 Сode看起来像这样:
private static byte[] getData1(){
int key = ...;
float[] buffer = new float[]{...};
byte[] array = new byte[buffer.length * 4];
byte[] bytes = new byte[4];
for (int i = 0; i < buffer.length; i++) {
bytes = ByteBuffer.allocate(4).putFloat(buffer[i]).array();
array[key + i * 4] = bytes[3];
array[key + i * 4 + 1] = bytes[2];
array[key + i * 4 + 2] = bytes[1];
array[key + i * 4 + 3] = bytes[0];
}
return array;
}
在将数组发送到FileOutputStream之前,数组看起来像这样(从调试中获取):
这怎么可以,我该如何解决这个问题?
答案 0 :(得分:0)
事实证明,所有代码都能正常运行。邮件客户端在发送过程中中断了文件。