title: downloading xml, delete bom and encode utf8
body: <p>I am downloading an XML from an FTP Server. And i have to prepare it for my SAX Parser. For this i need to delete the BOM byte and encode it as UTF-8. But somehow it doesnt work with every file. </p>
  
  <p>Here is my code for the two functions:</p>
  
  <pre><code>public static void copy(File src, File dest){
  
      try {
          byte[] data = Files.readAllBytes(src.toPath());
  
          writeAsUTF8(dest, skipBom(data));
  
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  
  private static void writeAsUTF8(File out, byte[] data){
  
      try {
  
          FileOutputStream outStream = new FileOutputStream(out);
          OutputStreamWriter outUTF = new OutputStreamWriter(outStream,"UTF8");
  
          outUTF.write(new String(data, "UTF8"));
          //outUTF.write(new String(data));
          outUTF.flush();
          outStream.close();
          outUTF.close();
      }
      catch(Exception ex){
          ex.printStackTrace();
      }
  }
  
      private static byte[] skipBom(byte[] data){
  
      int skipBytes = getBomSize(data);
  
      byte[] tmp = new byte[data.length - skipBytes];
  
      for(int x = 0; x &lt; tmp.length; x++){
          tmp[x] = data[x + skipBytes];
      }
  
      return tmp;
  }
  </code></pre>
  
  <p>Any ideas what am i doing wrong?</p>