【问题标题】:Edit specific bytes in a binary file - Java编辑二进制文件中的特定字节 - Java
【发布时间】:2014-02-07 14:33:38
【问题描述】:

我想知道如何在 Java 中编辑二进制文件中的特定字节。

示例,执行前的二进制文件:

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

刚才,我在modifiedByteArray[128]中给byteArray3[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,特定字节数组的起始位置。

关于它的解决方案?谢谢:)

【问题讨论】:

  • 你看过 RandomAccessFile 吗?
  • 你只想要一个随机访问文件而不是一个输出流吗?
  • 是的,我认为:X,我不知道随机访问文件。它是如何工作的?

标签: java inputstream binaryfiles outputstream randomaccessfile


【解决方案1】:

我就是想要这个,谢谢大家:

//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();

【讨论】:

    猜你喜欢
    • 2020-03-21
    • 2017-07-26
    • 1970-01-01
    • 2016-10-04
    • 2013-05-13
    • 1970-01-01
    • 2013-01-10
    • 2013-05-22
    • 2020-08-23
    相关资源
    最近更新 更多