title: Reading from one byte file returns 0xEF 0xBF 0xBD
body: <p><strong>Solved</strong>, accepted answer below because it pointed me at checking how my file got corrupted. Please read the end of this question for the Maven reason.</p>
  
  <p>I created a 1-byte file containing the byte <code>0xA8</code>. I'm trying to read it into any Java structure that will allow me to work with it later. I know bytes in java are signed so any value from <code>0x80</code> through <code>0xFF</code> will be interpreted negative.</p>
  
  <pre><code>import java.io.DataInputStream;
  import java.io.EOFException;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  public class Test {
      public static void main(final String[] args) throws IOException {
          // 0xA8.hex contains one byte 0xA8.
          final File inputFile = new File(Test.class.getClassLoader().getResource("0xA8.hex").getPath());
          final FileInputStream fin = new FileInputStream(inputFile);
          final DataInputStream dis = new DataInputStream(fin);
          int read = dis.readUnsignedByte();
          System.out.println(read + ", hex: " + Integer.toHexString(read));
  
          while (true) {
              try {
                  read = dis.readUnsignedByte();
                  System.out.println("read more: " + read + ", hex: " + Integer.toHexString(read));
              } catch (final EOFException ignored) {
                  break;
              }
          }
      }
  }
  </code></pre>
  
  <p>There probably is something <em>really</em> simple I'm missing, but I can't wrap my head around it.. The program above outputs:</p>
  
  <pre><code>239, hex: ef
  read more: 191, hex: bf
  read more: 189, hex: bd
  </code></pre>
  
  <p>The <code>0xA8.hex</code> file is a 1-byte file I created myself using a hex editor. The contents of it really is one single byte:</p>
  
  <pre><code>drvdijk@macmine:~/$ hexdump 0xA8.hex 
  0000000 a8                                             
  0000001
  </code></pre>
  
  <p>Why, and how can I make it read just one (possibly cast to unsigned) byte?</p>
  
  <h1>Solution</h1>
  
  <p>I use Maven, and in the <code>pom.xml</code> I had a section:</p>
  
  <pre><code>&lt;build&gt;
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
      &lt;!-- ... --&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>The <code>0xA8.hex</code> file I was using got filtered by Maven, entering the replacement character (0xEF 0xBF 0xBD) where my <code>0xA8</code> used to be. I now updated the <code>pom.xml</code> to the following:</p>
  
  <pre><code>&lt;build&gt;
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;excludes&gt;
                  &lt;exclude&gt;**/*.hex&lt;/exclude&gt;
              &lt;/excludes&gt;
          &lt;/resource&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;filtering&gt;false&lt;/filtering&gt;
              &lt;includes&gt;
                  &lt;include&gt;**/*.hex&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
      &lt;!-- ... --&gt;
  &lt;/build&gt;
  </code></pre>