Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Writting Greek text in xml file (without Netbeans) - issue.

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Writting Greek text in xml file (without Netbeans) - issue.

    Hi,

    i have create a java program, which - generally - reads, put in a diferent hierarhy and writes some string to a xml file.
    Some of the files have Greek characters. When i run it with (my personal favorite) Netbeans, all process is just fine.

    But when i run it just from .jar (the same jar which netbeans create), then all Greek character look like more as ... hieroglyphics..

    At start, i thought that it was my mistake. So i make this change at code:
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath),"UTF8"));

    Unfortunally this make no difference. I try also to change encoding ("ISO8859_7" , "Cp1253") but result was the same and worse..

    I concluded that something done by Netbeans and works the process correctly. Perchaps an option?
    It is need to compile and run it with .bat file, so .. any ideas what should i do to fix this?

    Thank you for your time.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    Try setting the character encoding of the OutputStreamWriter and corresponding InputStreamWriter to UTF-16

  3. The Following User Says Thank You to copeg For This Useful Post:

    g3orge (September 23rd, 2011)

  4. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    Thank you for the answer.
    I tried it but the results are the same..

    I wonder if is there any option for the .bat file, to "drive" the writing of files on an specific encoding?

  5. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    Have you tried printing the characters on the console before writing them? It would be interesting to see if they are already scrambled. You can set the default charset with the option '-Dfile.encoding=UTF-8' or something like that.

  6. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    Quote Originally Posted by Sean4u View Post
    Have you tried printing the characters on the console before writing them? It would be interesting to see if they are already scrambled.
    I just try it. In the console of Netbeans appear normal. But in console (CMD) looks like in file, damaged.
    After that, i open the file (xml) with the notepad, wordpad, notepad++. In any of those three the characters are ok.

    Because of xml file, i use kXML2 pull parser to load my data. But,even if that parser ruin greek characters.. Should not be so in the Νetbeans?

  7. #6
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    The reason I suggested you do that is to see whether the data is mangled on output or input. If it's mangled on the console then it must be mangled on input. Did you try the command-line setting for file.encoding?

  8. The Following User Says Thank You to Sean4u For This Useful Post:

    g3orge (September 23rd, 2011)

  9. #7
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Writting Greek text in xml file (without Netbeans) - issue.

    Problem Solved! I put - as you recommend - on bat file:

    Set JAVA_TOOL_OPTIONS= -Dfile.encoding=UTF8

    Thanks for all the help and guidance!

Similar Threads

  1. Double always == 0! And a Javadoc issue! (Using NetBeans)
    By CameronFaust in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 11th, 2011, 12:22 AM
  2. Text file to text area and Radiobuttons?
    By donaldmax in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 27th, 2011, 04:45 AM
  3. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  4. Write to pdf file with pdfbox with greek encoding
    By javment in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 16th, 2011, 08:57 AM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM