Skip to Main Content

Java SE (Java Platform, Standard Edition)

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!

reading rtf file - encodin charset problem

843805Jan 7 2007 — edited Feb 15 2007
Hello!
I need to read rtf file. I use JTextPane and RTFEditorKit, but I can't guess correct encoding... some characters aren't displayed properly.
This is the beginning of my sample rtf file:

{\rtf1\ansi\ansicpg1250\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1045\deflangfe1045{\fonttbl{\f0\froman\fcharset238\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f38\froman\fcharset0\fprq2 Times New Roman;}

and here is my code (I thought that encoding should be cp1250 but it's not working):
JTextPane editor = new JTextPane();
RTFEditorKit m_kit = new RTFEditorKit();
InputStream ins = new FileInputStream(new File("Koshmar.rtf"));
InputStreamReader in = new InputStreamReader(ins,"Cp1250");
StyledDocument m_doc = new DefaultStyledDocument(new StyleContext());

m_kit.read(in, m_doc, 0);

editor.setDocument(m_doc);
Another problem is that first I would like to find out in which encoding is given file and then read it using this encoding.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2007
Added on Jan 7 2007
17 comments
1,682 views