RTFEditorKit - Write to RTF File

Hi,
I am looking at writing the BLOB from database which is an rtf data to write to RTF file.
I am trying to use the RTFEditorKit for the same and was struck with the write API it provides.

write API takes the outstream and Document, all I have is Inputstream or bytestream from database - how do I convert the stream data to a Java Document object.

FileOutputStream outputStream = new FileOutputStream("C:\\blobfile.rtf");
            RTFEditorKit rtf = new RTFEditorKit();
            
            

            Document doc = rtf.createDefaultDocument();
           
            
                rtf.write(outputStream, lob.getBinaryStream(0, lob.length()), 0, doc.getLength());

Thank You,

Java can write binary data to a file just fine without RTFEditorKit's help.

FileOutputStream rtf = new FileOutputStream("blobfile.rtf");
    rtf.write(lob); // code may vary depending on what 'lob' actually is
    rtf.close();

Problem is it's writing the raw data which is with all the tags, It's not recognizing as rtf format data, when i open the file in RTF editor i see all the tags and content instead of just content, any way i can eliminate?

You asked for 'writing to a file'. You can do that with FileOutputStream. Did you actually mean 'open in RTFEditorKit'?

My suggestion for that would be to write to a file with FileOutputStream, close it, then use RTFEditorKit to open the file.

It's my bad, i am working on a corrupted rtf file and was trying all sort of things. The binary stream works if the file is not corrupted.

Thank You for the reply.

If the file is too corrupted to make sense of, you'll have to fix it first.