-1
我試圖從二進制.dat文件讀取日期(6整數的集合)和溫度(雙精度)。從二進制文件讀取int不正確Java
多次嘗試後,我終於得到了該文件的工作階段,但它在我無法識別的格式返回int。例如。日期2017年3月2日11:33,和溫度3.8被讀作:
措施:515840-1024-1024 2816 8512 241591910 溫度:1.9034657819129845E185
任何想法,如何更改密碼?
public void readFile() {
try {
DataInputStream dis = null;
BufferedInputStream bis = null;
try {
FileInputStream fis = new FileInputStream(fileLocation);
int b;
bis = new BufferedInputStream(fis);
dis = new DataInputStream(fis);
while ((b = dis.read()) != -1) {
System.out.println("Measure : " + dis.readInt() + "-"
+ dis.readInt() + "-" + dis.readInt() + " " +
dis.readInt() + " " + dis.readInt() + " "
+ dis.readInt() + " Temperature: "+ dis.readDouble());
}
} finally {
dis.close();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (EOFException f) {
f.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} // readFile
很好,非常感謝 – Turo 2015-02-12 00:19:53