title: Read an image using FileInputStream in Java
body: <p>I am trying to use fileInputStream to read an image in and write out to produce another image. I want to read pixels in and then change pixels to get an left-right flip image. However, now I only read image in and write it directly out, I get something wrong. After using ultra edit, here is what i get from first 4 bytes:<br>
  <strong>original image:42 4D 7A 95<br>
  new image:42 4D 7A 3F</strong><br>
  It seems that every byte which its MSB is 1 has been changed to <strong>3F</strong>. I know every data type in Java is signed, and also I already have tried to and 0xff to every byte.  </p>
  
  <pre><code>public static void imageOut() {
     try {
          FileInputStream in = new FileInputStream(new File(getPath()));
          int[] temp = new int[fSize];
          int i = 0;
  
          while (in.available() &gt; 0) {
              temp[i] = in.read();
              i++;
          }
  
          OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(getOutputPath()));
          for (int j = 0; j &lt; temp.length; j++) {
              out.write(((byte)temp[j]));
          }
  
          out.flush();
          out.close();
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>