目前已定位到是因為C#中的byte范圍是0到255,而java中byte值為-128到127導致的錯誤。
嘗試過使用C#的sbyte來解決:
bw1 = new BinaryWriter(new FileStream("C:\\Users\\DELL\\Desktop\\SpatialIndex\\ctest1.bin", FileMode.Create));?bw2 = new BinaryWriter(new FileStream("C:\\Users\\DELL\\Desktop\\SpatialIndex\\ctest2.bin", FileMode.Create));??????
??????????byte[] bits=BitConverter.GetBytes(501751.060001268);//測試數據??????????????? sbyte[] bitsb = new sbyte[8];??????????????? for (int i = 0; i < bits.Length; i++)??????????????? {??????????????????? byte abyte = bits[i];??????????????????? if (abyte > 127)??????????????????? {??????????????????????? bitsb[i] = (sbyte)(abyte - 256);??????????????????? }??????????????????? else??????????????????? {??????????????????????? bitsb[i] = (sbyte)abyte;??????????????????? }??????????????????? bw1.Write(bitsb[i]);??????????????????? bw2.Write(bits[i]);??????????????? }?
?
但是寫入后對比,兩個文件中的內容還是一樣,并沒有生成為java二進制格式。
?
不知道有哪位高人也遇到并解決過類似問題。???????????
C#中將double值變成二進制然后寫入文件,Java中載入該文件讀取此二進制double值時不正確
慕碼人2483693
2018-12-06 18:10:00