title: javax.swing.text.rtf.RTFEditorKit / RTF is an 8-bit format
body: <p>I need a simple converter for HTML2RTF and
  i try to run follow code.... but i got a error for this code example</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import java.io.ByteArrayInputStream;
  import java.io.StringWriter;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  import javax.swing.text.Document;
  import javax.swing.text.html.HTMLEditorKit;
  import javax.swing.text.rtf.RTFEditorKit;
  
  public class converter {
      private static Pattern htmlTrimPattern = Pattern.compile(".*&lt;body&gt;(.*)&lt;/body&gt;.*", Pattern.DOTALL);
  
      public static void main(String[] args)
      {
  
  
          toRtf("&lt;!DOCTYPE html&gt;\n" +
                  "&lt;html&gt;\n" +
                  "&lt;body&gt;\n" +
                  "\n" +
                  "&lt;h1&gt;My First Heading&lt;/h1&gt;\n" +
                  "\n" +
                  "&lt;p&gt;My first paragraph.&lt;/p&gt;\n" +
                  "\n" +
                  "&lt;/body&gt;\n" +
                  "&lt;/html&gt;\n");
  
      }
  
      public static String toRtf(String html) {
          ByteArrayInputStream input= new ByteArrayInputStream(html.getBytes());
          StringWriter writer = new StringWriter();
          try {
              RTFEditorKit rtfEditorKit = new RTFEditorKit();
              HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
              Document htmlDoc = htmlEditorKit.createDefaultDocument();
              htmlEditorKit.read(input, htmlDoc, 0);
              rtfEditorKit.write(writer, htmlDoc, 0, htmlDoc.getLength());
          } catch (Exception ex) {
              System.out.println("Error"+ex);
          }
          System.out.println(writer.toString());
          return writer.toString();
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Errorjava.io.IOException: RTF is an 8-bit format
  </code></pre>
  
  <p>what am I doing wrong? google is in this case not my friend and i hope you can help me :)</p>