title: Java JTextPane RTF Save
body: <p>i have the following code trying to save the contents of a JTextPane as RTF. although a file is created in the following code but it is empty!</p>
  
  <p>any tips regarding what am i doing wrong? (as usual dont forget im a beginner!)</p>
  
  <pre><code>if (option == JFileChooser.APPROVE_OPTION) {
  ////////////////////////////////////////////////////////////////////////
  //System.out.println(chooser.getSelectedFile().getName());
  
  //System.out.println(chooser.getSelectedFile().getAbsoluteFile());
  ///////////////////////////////////////////////////////////////////////////
  
  StyledDocument doc = (StyledDocument)textPaneHistory.getDocument();
  RTFEditorKit kit = new RTFEditorKit();
  
  BufferedOutputStream out;
  
  try {
       out = new BufferedOutputStream(new FileOutputStream(chooser.getSelectedFile().getName()));
  
       kit.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());
  } catch (FileNotFoundException e) {
  } catch (IOException e){
  } catch (BadLocationException e){
  }
  }
  </code></pre>
  
  <p>EDIT: HTMLEditorKit if i use HTMLEditorKit it works and thats what i really wanted. SOLVED!</p>