title: Reading a block of bytes from one file and writing to other until all blocks are read?
body: <p>I am working a project in which I have to play with some file reading writing tasks. I have to read 8 bytes from a file at one time and perform some operations on that block and then write that block to second file, then repeat the cycle until first file is completely read in chuncks of 8 bytes everytime and the after manipulation the data should be added/appended to the second. However, in doing so, I am facing some problems. Following is what I am trying:</p>
  
  <pre><code>private File readFromFile1(File file1) {
  
      int offset = 0;
      long message= 0;
  
      try {
          FileInputStream fis = new FileInputStream(file1);
          byte[] data = new byte[8];
          file2 = new File("file2.txt");
          FileOutputStream fos = new FileOutputStream(file2.getAbsolutePath(), true);
          DataOutputStream dos = new DataOutputStream(fos);
  
          while(fis.read(data, offset, 8) != -1)
          {
              message = someOperation(data); // operation according to business logic
              dos.writeLong(message);
          }
          fos.close();
          dos.close();
          fis.close(); 
      } catch (IOException e) {
          System.out.println("Some error occurred while reading from File:" + e);
      }
      return file2;
  }
  </code></pre>
  
  <p>I am not getting the desired output this way. Any help is appreciated.</p>