Results 1 to 3 of 3
Thread: Displaying Unicode Characters
- 02-22-2011, 12:35 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Displaying Unicode Characters
I wrote a java program that writes strings to a file. The strings contain foreign language characters. When I run the program in Windows, the output file shows the foreign characters. However, when I attempt the same operation in Linux, the output file shows a white question mark in a black background instead of the foreign characters.
The same Linux system could display the foreign characters if I copy the output file from Windows to Linux. I tried to create the output file using gedit that my program would then add additional strings to and chose Unicode-32 for encoding but still the same problem.
I read online that Java uses Unicode, while other sources states UTF-16.
Some of the encoding available on gedit (text editor) are Unicode UCS-2, Unicode UTF-32, Unicode UTF-16LE, Unicode UTF-16BE, Unicode UTF-16, Unicode UTF-7, Unicode UCS-4.
What could I do to get the program to display the foreign language characters from output text file?
Your help will be much appreciated,
Mike
- 02-22-2011, 09:54 PM #2
Member
- Join Date
- Dec 2008
- Posts
- 64
- Rep Power
- 0
What encoding are you using to write to the file? Can you paste your code here that shows how you are writing to the file. Also you need to make sure that the encoding you use to write is the same you use to read, Windows uses CP1252 by default whereas Unix uses UTF-8 usually. Simply write your string to the file in UTF-8 format and it should work for both.
For instance you could do:
Java Code:myFileOutputSteram.write(myString.getBytes("UTF-8");
- 02-24-2011, 02:44 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Thank you for taking the time to reply!
I don't specify the encoding. I'm using the FileWriter class which doesn't have a constructor with encoding parameter. The only reason I'm using it is because it has a write method that takes a string.
I will try FileWriter.write(stringToWrite.getBytes("UTF-8"));
I will do the same for FileReader....hopefully it will solve the problem.
Thanks again,
Mike
Similar Threads
-
how do java handle russian characters=unicode in Files&Streams code?
By lse123 in forum Advanced JavaReplies: 23Last Post: 08-12-2010, 09:59 AM -
Problem with writing unicode characters in a file
By ze snow in forum New To JavaReplies: 1Last Post: 02-23-2010, 10:47 PM -
Problem displaying UNICODE characters on a JLabel
By lumpy in forum New To JavaReplies: 2Last Post: 02-15-2010, 06:49 AM -
Form Based Authentication fails with unicode characters
By davesquire in forum Java ServletReplies: 1Last Post: 09-25-2009, 06:00 PM -
writing and reading unicode characters from a file
By ranoosh in forum Advanced JavaReplies: 4Last Post: 09-28-2008, 04:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks