title: Java - why does readAllBytes return incorrect byte codes?
body: <p>I have the following problem. I'm using Java to create a byte array from a file. So I do the following:</p>
  
  <pre><code>byte[] myByteArray = Files.readAllBytes(filename);
  </code></pre>
  
  <p>However, for many of the bytes it is returning incorrect/negative values.</p>
  
  <p>For instance, if I test using javascript, to read every byte of a file e.g.</p>
  
  <pre><code>    function readbytes(s){
      var f = new File(s);
      var i,a,c;
      var d = [];
      if (f.isopen) {
          c = f.eof;
          for(i=0;i&lt;c ;i++){ 
              a = f.readbytes(1); 
              d.push(a);
          }   
          f.close();
          return d;
      } else {
          post("could not open file: " + s + "n");
      }
  }
  </code></pre>
  
  <p>(readbytes is a function in the program Im using that gives the byte at a specific position).</p>
  
  <p>This returns the correct bytes</p>
  
  <p>So Im wondering, why does java return incorrect codes? Is this something to do with unsigned values?</p>