Results 1 to 4 of 4
  1. #1
    xlomo is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Encoding Problems in JRE

    Hello forum, I Have a strange problem regarding Character Encoding while running in JRE, I need to save in a text file some text and I have some special characters in it for control reasons, for ex. the char ( ◙ ).

    My problem is that while this works when I run my program through the NetBeans, when I try to run the Jar file with JRE the Special characters become the (TM) char.
    Why do you think that happens ?

    Thanks in advance.

  2. #2
    break. is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default

    I might be totally wrong, but have you tried specifically selecting the character encoding for output? I had this problem when I passed some commandline args[] to program and they turned out odd. I solved the problem using PrintStream. Like so:

    System.out.println("C:\\DO.EXE " + args[0]);
    --> prints out badly, C:\DO.EXE "Ei mõõritelty"

    message = "C:\\DO.EXE" + args[0];
    PrintStream ps = new PrintStream(System.out, true, "Cp852");
    ps.println(message);
    --> prints out correctly, C:\DO.EXE "Ei määritelty"

    Sun Java Supported Character Encodings

  3. #3
    xlomo is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    You might be right, I don't set a character encoding and maybe there are different defaults in sdk and in JRE,

    Java Code:
    final Transformer t = TransformerFactory.newInstance().newTransformer();
    OutputStream outputStream = new FileOutputStream(XmlFilePath);            
    t.transform(new DOMSource(document), new StreamResult(outputStream));
    this is the code that saves the file, can anyone tell me how to set the character Encoding ?

  4. #4
    xlomo is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    Solved,
    My problem was that before the code above, I converted byte to string without setting charset encoding.

    return new String(buffer);

    instead of

    return new String(buffer,"UTF-8");

Similar Threads

  1. Need encoding for Korean
    By RamaNalayini in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2010, 02:34 PM
  2. arabic encoding in url
    By echoe_echoe in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-06-2010, 08:10 AM
  3. problem in encoding
    By jaysh in forum NetBeans
    Replies: 0
    Last Post: 08-26-2010, 08:07 AM
  4. Encoding Problem
    By GJ! in forum Advanced Java
    Replies: 6
    Last Post: 01-12-2010, 08:09 PM
  5. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 12:22 AM

Tags for this Thread

Posting Permissions

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