Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

RTFEditorKit - Write to RTF File

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-21-2017   -   Original Discussion by vijaykrc
vijaykrc's Unix or Linux Image
vijaykrc vijaykrc is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 21 September 2017, 4:56 PM EDT
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
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:
RTFEditorKit - Write to RTF File Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-21-2017 at 12:59 PM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 09-21-2017   -   Original Discussion by vijaykrc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
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();

Sponsored Links
    #3  
Old Unix and Linux 09-21-2017   -   Original Discussion by vijaykrc
vijaykrc's Unix or Linux Image
vijaykrc vijaykrc is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 21 September 2017, 4:56 PM EDT
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Corona688 View Post
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 Unix and Linux 09-21-2017   -   Original Discussion by vijaykrc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
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.
Sponsored Links
    #5  
Old Unix and Linux 09-21-2017   -   Original Discussion by vijaykrc
vijaykrc's Unix or Linux Image
vijaykrc vijaykrc is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 21 September 2017, 4:56 PM EDT
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #6  
Old Unix and Linux 09-22-2017   -   Original Discussion by vijaykrc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
If the file is too corrupted to make sense of, you'll have to fix it first.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help to write a shell script to convert text file to excel file. akabhinav18 Shell Programming and Scripting 8 10-13-2015 06:18 AM
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 08: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 05: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 03:47 PM
read/write,write/write lock with smbclient fails swatidas11 IP Networking 1 03-05-2010 10:26 AM



All times are GMT -4. The time now is 03:54 AM.