Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to present a content of a documeent as a String?

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I have a certain byte array - byte[] b - that contains a content I've read from a certain word file.
I would like to present this content as a String, is it possible to do it?
 
Well you can construct a String from a byte[] arary like this :

String s = new String(byteData);

But if the byte data is actually a MS Word document, then it won't actually be sensible/readable data.

You need a programme that understands MS formats (like Word, or OpenOffice).

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Is there an open source code that can "Understand" word?
I am familiar with the POI project of apache but it is in it's early stages in Word...
 
Know what? Let's do it more easy (I think): Assume these are rtf files, how can I do it now?
 
Same as before - yes you can convert them to a String, but the data will be unintelligable.

>>> Is there an open source code that can "Understand" word?
The only one I know of is POI.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Well yes, but you cannot just "convert a byte[] to a String" ... but if you want to play around with the javax.swing.text.rtf package, then have a go !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
You may still be able to use the API - Swing packages can be used in headless mode ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
To be more specific: How do I create an idependant Document object (not related to a Swing component) that contains the rtf text?
 
Sorry ... no idea ... guess you'll have to have a bit of trial and error :)

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
10X but this Object converts to org.w3c.dom.Document, I need javax.swing.text.Documet...
 
Again, the document here is taken from JEditorPane which is a swing object. As I specified above, I am writing this code for the web environment (J2EE), therefore I need an Independant Document object and not one which is bound to a swing object.

Roy
 
Found the solution:

RTFEditorKit rtf = new RTFEditorKit();
javax.swing.text.Document doc = rtf.createDefaultDocument();
 
Oh, I see, so I imagine you asked Sun to move RTFEditor kit from swing packages ...

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top