2012-06-17 45 views
1

我哈瓦二進制文件是這樣的:如何用java讀取二進制文件中的dword?

offset | size/type | Description 
-------+-----------+----------------------------------------------------------- 
0x0000 | 28 chars | zero terminated string 
0x001c | 1 dword | fileoffset of first compressed data block (header size) 
0x0020 | 1 dword | overall size of compressed file 

我可以讀取28個字符的字符串。但我不知道如何讀取一個雙字並將其存儲爲int。

回答

2

DataInputStream.readFully()和.readInt()。儘管如此,您可能需要對(未指定的)字節順序做些什麼。如果這是一個問題,則在設置適當的字節順序後,ByteBuffer.getInt()。

+0

謝謝你的幫助。使用ByteOrder.LITTLE_ENDIAN解決了我的問題。 – user1461256