Results 1 to 7 of 7
Thread: Encoding Problem
- 11-22-2008, 05:10 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
Encoding Problem
To begin with this might no be advanced enough for the advanced forum. as I am new to this forum I am unsure where to draw the line between advanced and beginner... Anyway, here is my problem.
I am using FileReader to read data from an xml-file. However when the data is read the swedish characters (it's a swedish text) å,ä,ö are converted to ,Ã¥ ,ä ,ö when using default encoding (which I assume is Unicode in java).
I figured there might be some problem with the encoding so after I had read the file I tried re-coding the text with different encodings, at first UTF-encoding and then Cp1252 as that was the string returned by get.Encoding(), however the problem persists.
Currently I am at loss as to why my brilliant program (irony) isn't working as it should. Do I have to choose an encoding when reading the file or is it so that xml uses a special encoding? ( I have found no encoding declaration at the beginning of the document...)
All help will be greatly appreciated, a nod in the right direction would be more than enough for you to earn my gratitude.
- 11-22-2008, 06:49 PM #2
Suggestion...
This might help;
Converting Non-Unicode Text (The Java™ Tutorials > Internationalization > Working with Text)
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
-
How do you know that the data is converted? Are you outputting your text to the console? to a file? to a Swing JTextArea? What font are you using, and does it support your character set?
- 11-22-2008, 09:07 PM #4
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
I think I have checked that page but I'll check it again in case I have misunterstood something.
I am simply using Filewriter to write it to a file and where there is an å,ä or ö in the original file there is a Ã¥ ,ä or ö in the created file. I have however also tried outputting it directly to the console, however the problem is still there.
Originally Posted by Fubarable
-
Rather than using a FileReader and/or FileWriter, try using an InputStreamReader constructed on a FileInputStream. The InputStreamReader should be constructed with the correct Charset. Same for FileOutputStream and OutputStreamWriter.
Have a look here: Java Programming - String charset encoding decoding
and here: Java Programming - I'm having some problems understanding FileReader class
another great reference:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
- 11-23-2008, 12:03 AM #6
Member
- Join Date
- Nov 2008
- Posts
- 3
- Rep Power
- 0
I love you people, it works now. I also must say that the last link was a both amusing and enlightening read.
- 01-12-2010, 08:09 PM #7
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Same issue
Hi GJ,
I have the exact same issue that you have faced.I am reading swedish characters from a db and getting the same issues that you have posted.Do you remember which charset encoding you have used to solve this issue. I am using OutputStreamWriter and FileOutputStream classes to write to the output file.
Thanks,
N
Similar Threads
-
Lucene Indexer Encoding problem
By svirid in forum LuceneReplies: 5Last Post: 02-18-2009, 09:26 AM -
How to specify character encoding in JavaMail?
By jfcup in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 10-24-2008, 07:55 PM -
encoding special characers in jsp
By nanimtech in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 05-06-2008, 01:22 PM -
Some help with encoding...
By nm123 in forum NetworkingReplies: 0Last Post: 04-15-2008, 12:22 AM -
Missing text encoding
By talgreen in forum EclipseReplies: 0Last Post: 03-30-2008, 08:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks