title: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 4-byte UTF-8 sequence (XML)
body: <p>I am getting this Exceptoin and the problem is because I input characters that are utf-8 encoded.</p>
  
  <p>At the top of my XML file is say : <code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</code> 
  And I have added encoding. but stil I get this exception.        </p>
  
  <pre><code> //Set the format
      Format format = Format.getPrettyFormat();
      format.setEncoding("UTF-8");
      XMLOutputter xmlOutput = new XMLOutputter(format);
      // Create a new file and write XML to it
      xmlOutput.output(doc, new FileOutputStream(new File(XMLEditorService
              .getXMLEditorService().getFile())));
  </code></pre>
  
  <p>The error seems to occur when I parse the file : </p>
  
  <pre><code>Document xmlDocument = builder.parse(file);
  
  com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 4-byte UTF-8 sequence.
      at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
      at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
  </code></pre>
  
  <p>How to solve this?</p>