改变一个特定字节在一个文件 [英] Changing a specific byte in a file
本文介绍了改变一个特定字节在一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个java功能,这将改变1个字节的大文件。我怎样才能读取和写入到特定地址中使用Java在Android上的文件?我曾尝试fis.read(BYTE B [],整数关,INT LEN),我每次都遇到一个强制关闭。
I am trying to write a java function that will change 1 byte in a large file. How can I read in and write to a specific address in a file with java on android? I have tried fis.read(byte b[], int off, int len) and I get a force close every time.
推荐答案
使用<一个href="http://developer.android.com/reference/java/io/RandomAccessFile.html"><$c$c>RandomAccessFile$c$c>.
开球例如:
RandomAccessFile raf = new RandomAccessFile(file, "rw");
try {
raf.seek(5); // Go to byte at offset position 5.
raf.write(70); // Write byte 70 (overwrites original byte at this offset).
} finally {
raf.close(); // Flush/save changes and close resource.
}
这篇关于改变一个特定字节在一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文