Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Encoding of file output different from within netbeans to executing .jar

807580Jul 20 2010 — edited Jul 20 2010
I am writing a file encryption program at the moment, and am having issues with how the file is stored.

When running the program in netbeans, everything works fine. However, when running the .jar file from the command line, or in explorer it does not.

I have worked out where the problem lies: When running the program from within netbeans, the file is made using a different encoding. Notepad++ tells me that when run from within netbeans, the character encoding is "ANSI as UTF-8", whereas when run standalone, the file is generated using "ANSI" (and shows extra characters as a result.)

Output was originally performed using
PrintStream fout = new PrintStream(filename); 
but I changed it to
BufferedWriter fout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF8")); 
but still the same result.

So how do I force the standalone .jar file to use UTF8 when the above isn't doing it?



tl;dr - How do I force standalone .jars to use UTF8 encoding on output when
BufferedWriter fout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF8")); 
doesn't work?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2010
Added on Jul 20 2010
10 comments
511 views