RTFEditorKit - Write to RTF File

Tags
programming

 
Thread Tools Search this Thread
# 1  
Old 09-21-2017
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.

Code:
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,


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-21-2017 at 01:59 PM.. Reason: Added CODE tags.
# 2  
Old 09-21-2017
Java can write binary data to a file just fine without RTFEditorKit's help.

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

# 3  
Old 09-21-2017
Quote:
Originally Posted by Corona688
Java can write binary data to a file just fine without RTFEditorKit's help.

Code:
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?
# 4  
Old 09-21-2017
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.
# 5  
Old 09-21-2017
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.
# 6  
Old 09-22-2017
If the file is too corrupted to make sense of, you'll have to fix it first.

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Ksh: How to write the log file simultaneously when .sql file executes by UNIX process Hima_B Shell Programming and Scripting 1 12-30-2016 01:07 AM
Need help to write a shell script to convert text file to excel file. akabhinav18 Shell Programming and Scripting 8 10-13-2015 07:18 AM
Replacing duplicated extensions, like .rtf.rtf OmarKN UNIX for Dummies Questions & Answers 6 11-05-2014 04:22 PM
Compare 2 text file with 1 column in each file and write mismatch data to 3rd file Divya Nochiyil Shell Programming and Scripting 10 11-04-2013 09:45 AM
Need to search a particular String form a file a write to another file using perl script Raysf Shell Programming and Scripting 2 09-20-2013 06:22 PM
Match list of strings in File A and compare with File B, C and write to a output file in CSV format asnandhakumar Shell Programming and Scripting 6 10-11-2012 04:47 PM
Extract data from an XML file & write into a CSV file ss_ss Shell Programming and Scripting 2 04-18-2010 10:21 PM
Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ??? alex_5161 Programming 2 03-08-2010 04:36 PM
read/write,write/write lock with smbclient fails swatidas11 IP Networking 1 03-05-2010 11:26 AM
how to convert XLS to CSV and DOC/RTF to TXT prvnrk Shell Programming and Scripting 1 04-23-2009 03:47 PM
looking for convert rtf to pdf utility umen UNIX and Linux Applications 2 03-04-2009 05:07 AM
Problem to send rtf inline body srik_ux UNIX for Dummies Questions & Answers 7 05-30-2008 12:30 PM
embedded exe file into rtf file rawatds Shell Programming and Scripting 1 12-06-2004 06:52 AM
RTF files can they be converted once they are on linux system moxxx68 Windows & DOS: Issues & Discussions 7 09-12-2004 02:26 PM
converting PDF to text, rtf doc format saurya_s UNIX for Advanced & Expert Users 1 04-23-2004 04:25 PM