Creating UTF-8 files in Java from a runnable Jar
        Posted  
        
            by RuntimeError
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by RuntimeError
        
        
        
        Published on 2010-06-13T16:56:07Z
        Indexed on 
            2010/06/13
            17:02 UTC
        
        
        Read the original article
        Hit count: 245
        
I have a little Java project where I've set the properties of the class files to UTF-8 (I use a lot of foreign characters not found on the default CP1252).
The goal is to create a text file (in Windows) containing a list of items. When running the class files from Eclipse itself (hitting Ctrl+F11) it creates the file flawlessly and opening it in another editor (I'm using Notepad++) I can see the characters as I wanted.
+--------------------------------------------------+
¦                          Universidade2010 (18/18)¦
¦                                         hidden: 0¦
+--------------------------------------------------¦
But, when I export the project (using Eclipse) as a runnable Jar and run it using 'javaw -jar project.jar' the new file created is a mess of question marks
????????????????????????????????????????????????????
?                          Universidade2010 (19/19)?
?                                         hidden: 0?
????????????????????????????????????????????????????
I've followed some tips on how to use UTF-8 (which seems to be broken by default on Java) to try to correct this so now I'm using
Writer w = new OutputStreamWriter(fos, "UTF-8");
and writing the BOM header to the file like in this question already answered but still without luck when exporting to Jar
Am I missing some property or command-line command so Java knows I want to create UTF-8 files by default ?
© Stack Overflow or respective owner