private void writeDocument(Document doc,File f,String characterSet,String lineSeparator) throws IOException {
  LFWriter out=new LFWriter(new OutputStreamWriter(new FileOutputStream(f),characterSet));
  out.setLineSeparator(lineSeparator);
  try {
    String sequence;
    for (int i=0; i < doc.getLength(); i+=256) {
      out.write(doc.getText(i,Math.min(256,doc.getLength() - i)));
    }
  }
 catch (  BadLocationException e) {
    throw new IOException(e.getMessage());
  }
 finally {
    out.close();
    undoManager.discardAllEdits();
  }
}

private void writeDocument ( Document doc , File f , String characterSet , String lineSeparator ) throws IOException { LFWriter out = new LFWriter ( new OutputStreamWriter ( new FileOutputStream ( f ) , characterSet ) ) ; out . setLineSeparator ( lineSeparator ) ; try { String sequence ; for ( int i = 0 ; i < doc . getLength ( ) ; i += 256 ) { out . write ( doc . getText ( i , Math . min ( 256 , doc . getLength ( ) - i ) ) ) ; } } catch ( BadLocationException e ) { throw new IOException ( e . getMessage ( ) ) ; } finally { out . close ( ) ; undoManager . discardAllEdits ( ) ; } }
writes a document into a file using the specified character set .
