5 Replies Latest reply: Jan 10, 2010 11:15 PM by 807580 RSS

    Getting problem while editing a binary file

      Hi All,

      I am trying to edit a binary file using Java.The file contain a string that I have to replace with some other string.For exanple let us assume following is the content of the file -

      õgëÓÌ©™ÿÿ ABC õgëÓÌ©™ÿÿ

      Here, I have to replace this ABC(a string) with some other string.Now,if the replace string length is more than 3(the length of exiting string) then, the binary file is generating some blank space at the end.

      My Code::
      //Here I am trying to insert "Hello" in place of "ABC".
      FileInputStream fis = null;
      fis = new FileInputStream(aFile);
      FileOutputStream to = new FileOutputStream(aF);
      byte[] aTes=new byte[1024];
      String str="Hello";

      byte[] buffer = new byte[4096];
      int bytesRead;
      while ((bytesRead = fis.read(buffer)) != -1) {
      to.write(buffer, 0, 5);
      to.write(buffer, 5, bytesRead);

      Plesae guide me to solve this problem.