2014-02-07 38 views
1

我想知道如何在Java中編輯二進制文件中的特定字節。編輯二進制文件中的特定字節 - Java

實施例,在執行前binaryfile:

byteArray1[128].. Represents a array of 128 bytes. 
byteArray2[128].. Other array of bytes 
byteArray3[128] 
byteArray4[128] 

剛纔我取一個新的數據到byteArray3 [128]在modifiedByteArray [128]。 執行後:

byteArray1[128] 
byteArray2[128] 
modifiedByteArray3[128] .. The array in that position was modified. 
byteArray4[128] 

我有這樣的事情代碼的文件中追加:

//PASSFILE -> binary passfile path 
FileOutputStream fileOutput = new FileOutputStream(PASSFILE, true); 
BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutput); 
long datos; 

// cipherText 128 bytes 
bufferedOutput.write(cipherText); 

我有這樣的數據:
modifiedData [128],在一個具體的新的密文在二進制文件中的位置。

offsetPosition,特定字節數組開始的位置。

關於它的解決方案?謝謝:)

+0

你有看的RandomAccessFile? –

+0

你只是想要一個隨機訪問文件,而不是輸出流? – user3109924

+0

是的我想:X,我ddnt知道隨機存取文件。怎麼運行的? – SerCrAsH

回答

0

我只是想這一點,感謝所有:

//PASSFILE -> binary file path 
RandomAccessFile raf = new RandomAccessFile(PASSFILE, "rw"); 

//Entrie = Array number to modify 
int offset = (entrie * 128); 

raf.seek(offset); 
// cipherText = 128 bytes of the new array for the speficic entrie 
raf.write(cipherText); 
raf.close();