Results 1 to 10 of 10
- 05-17-2011, 06:37 PM #1
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
UTF-8, Java, and text output to an RTF
I am coding my first commercial application and I'm working through bugs slowly but surely. Here's a problem I've run into:
I am having the character '▓' and others output to an RTF by this method:
When I open the output file in WordPad it prints a 'â–ˆ'. I have to use WordPad for this and I also have to have the block character. I'm coding a medical text-based application where the user will eventually look at a printout of a 96 well plate and line it up and the dark boxes represent a positive read and the light boxes represent negative reads. I have to use those because other characters aren't dark enough.Java Code:FileWriter outputStream = new FileWriter("output.rtf");
Any advice? I'm coding in eclipse.
Also, can you make it output with default font other than Times New?
I also have noticed in WordPad when I open the output file instead of showing a picture of a colored rtf in the tile bar it's just a regular text picture next to "output - Wordpad" on the top left. This only happens when I open this rtf and not another rtf I create in WordPad.Last edited by montag; 05-17-2011 at 06:51 PM.
- 05-17-2011, 06:44 PM #2
What is the hex/binary value of the block character?
Does Wordpad have any characters that it will display that looks like the block character?
- 05-17-2011, 06:55 PM #3
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
U+2588 █ e2 96 88 FULL BLOCK
I guess the hex value is e2 96 88 according to Unicode/UTF-8-character table
WordPad will display this character only if I copy and paste it in or change my outputStream to .doc and then save it as an rtf.Last edited by montag; 05-17-2011 at 06:59 PM.
- 05-17-2011, 07:15 PM #4
I copy and pasted the first line of your last post into Wordpad and saved it as Unicode text
and got the following in the .txt file:
It looks like the block character was written as 0x8825FFFE 55002B0032003500380038000900
8825 0900650032002000390036002000
3800 38000900460055004C004C002000
4200 4C004F0043004B00
Which is 2588 with reversed bytes.Last edited by Norm; 05-17-2011 at 07:17 PM.
- 05-17-2011, 08:32 PM #5
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
What does that mean exactly? It's reversing my unicode characters?
- 05-17-2011, 08:45 PM #6
Here's some code that will write a block to a txt file:
Java Code:// UTF-8 rules // 1110xxxx 10xxxxxx 10xxxxxx for 16 bits // 11101234 10567890 10123456 the bit positions(1 based) takes 3 bytes for 1 char // UTF-8 character U+2588 ¦ e2 96 88 FULL BLOCK char[] data = {'\u3e00', '\u2588', '<'}; // UTF16 - FEFF 003E 8825 003C <<< This shows the BLOCK in Wordpad with sqrs on each side // UTF16 - FEFF 3E00 8825 003C <<<< Shows > on left side of BLOCK // UTF8 - 3E E8 A0A5 3C <<< This shows: >è*¥< // UTF8 - FEFF 3E00 8825 003C <<<< This shows as > Block and a sqr !!!! OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("BlockUnicode.txt"), "UTF8"); out.write(data, 0, data.length); out.close();
- 05-17-2011, 09:27 PM #7
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
Thanks man. That helped a lot, although when I open it and run it in WordPad it still gives me those random characters. I ended up looking around thinking WordPad was the problem and I found AbiWord. I'm going to use AbiWord which is open source and seems a lot better than WordPad. The formatting is the exact same (unlike OpenOffice and MS Word) so I'm a fan, and it prints the blocks. Thanks again! Kudos.
- 05-17-2011, 09:40 PM #8
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
Also how do I set the default output font to Courier New at 12 pt?
- 08-01-2011, 06:59 PM #9
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
So I've come back with a new problem. I have virtually completed the backend and made it possible to open a text file with the correct UTF-8 formatting so I can see the black squares. I've since started my first GUI frontend for this. Now I'm trying to have it open in a JTextPane and I am not sure how to specify UTF-8 formatting again so I'm running into the same problem. Any advice? I'm going to keep doing research after lunch to see if I can figure it out. Would I have the FileReader specify UTF-8?
Thanks again,
montag
- 08-01-2011, 09:11 PM #10
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
I figured it out. It was all due to the reader and me not specifying UTF8.
I have yet to fix the buffer size. Thanks again Norm.Java Code:Reader in = new InputStreamReader(new FileInputStream(file), "UTF-8"); //Reader in = new FileReader(file); char[] buff = new char[40000096]; int nch; while((nch = in.read(buff, 0, buff.length)) != -1) { //jTextPane0.setDocument(new StyledDocument()); jTextPane0.setText(new String(buff, 0, nch)); }
Similar Threads
-
Writing a block of text as it is to output file
By bikashg in forum New To JavaReplies: 5Last Post: 05-29-2010, 11:38 PM -
Output to a text file
By sfe23 in forum New To JavaReplies: 4Last Post: 03-26-2009, 10:44 PM -
Centering text of output
By dch414 in forum New To JavaReplies: 2Last Post: 10-02-2008, 10:08 PM -
Text Output for a library
By dream_noir in forum Advanced JavaReplies: 0Last Post: 04-14-2008, 05:31 AM -
Simply output the result to a text file.
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks