Results 1 to 7 of 7
  1. #1
    GJ!
    GJ! is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Question 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.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Suggestion...

    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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?

  4. #4
    GJ!
    GJ! is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by CJSLMAN View Post
    This might help;
    Too low a post-count for quoting links...

    Luck,
    CJSL
    I think I have checked that page but I'll check it again in case I have misunterstood something.

    Quote Originally Posted by Fubarable
    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?
    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.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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!)

  6. #6
    GJ!
    GJ! is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    I love you people, it works now. I also must say that the last link was a both amusing and enlightening read.

  7. #7
    nshettys is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default 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

  1. Lucene Indexer Encoding problem
    By svirid in forum Lucene
    Replies: 5
    Last Post: 02-18-2009, 10:26 AM
  2. How to specify character encoding in JavaMail?
    By jfcup in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-24-2008, 08:55 PM
  3. encoding special characers in jsp
    By nanimtech in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 05-06-2008, 02:22 PM
  4. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 01:22 AM
  5. Missing text encoding
    By talgreen in forum Eclipse
    Replies: 0
    Last Post: 03-30-2008, 09:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •