Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

writing from jtextpane to an .rtf file

807588Feb 9 2007 — edited Jun 14 2009
I am wanting to write from a text pane either into a .rtf file and then into a byte array or directly from the jtextpane to a byte array as long as I could still reconstruct it later into an .rtf file and still keep the formatting.

I am currently trying this error

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.File.<init>(File.java:222)
at mmsiserver.notesApp.updatePatientNotes(notesApp.java:2198)
on the following code. I don't think that using the getText() is correct but didn't see anything in the api on how to read from the jtextpane, I am still fairly new to java and sometimes misread or read over pieces of the api...here is my code.
  try {
                FileInputStream input = new FileInputStream(new File(notesPane.getText()));
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                byte[] data = null;
                int count = 1;
                int numBytesRead = 0;
                while ((numBytesRead = input.read(buf)) != -1) {
                    output.write(buf, 0, numBytesRead);
                    count++;
                }
                
            data = output.toByteArray();
               output.close();
            input.close();

                FileOutputStream out = new FileOutputStream(new File("c:/hi.rtf"));
                out.write(data, 0, data.length);
                out.close();
Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2009
Added on Feb 9 2007
4 comments
586 views