public class BitEdit {
public void changeByte(File source, File target, int bytePos, int bufferSize, byte replace) throws FileNotFoundException, IOException{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
byte[] beforePos = new byte[bytePos];
byte[] buffer = new byte[bufferSize];
bis.read(beforePos);
beforePos[bytePos - 1] = replace;
bos.write(beforePos);
while ((bis.read(buffer)) != -1) {
bos.write(buffer);
}
bos.close();
bis.close();
}
public static void main(String[] args) throws IOException{
new BitEdit().changeByte(new File("C:\\blub.txt"), new File("C:\\blub2.txt"), 50, 1024, (byte)1);
}
}