embedding preferred encoding instruction into a java program
my problem continues from here utf-8 as output.Currently i am using:
PrintWriter bout = new java.io.PrintWriter(filename,"UTF-8");
and it still is not working .as @dacwe suggested,i used command line with
-Dfile.encoding=UTF-8
to execute my .jar file and it worked,where the desired utf-8 file output was created(no alphabets pro开发者_运维百科b).So i am thinking this workaround like how eclipse.exe works with .ini file in eclipse directory.can i wrap my java prog into exe and have the program to include the .ini file?or can someone suggest any workable idea?my program read csv file (from opencsv) and output as a text in UTF-8.
From this question: Parse CSV file containing a Unicode character using OpenCSV
You should use your CSVReader like this:
CSVReader reader=new CSVReader(
new InputStreamReader(new FileInputStream("d:\\a.csv"), "UTF-8"),
',', '\'', 1);
And you do not need to set any environment properties like file.encoding
or anything else.
Use a shell script or batch file to pass the JVM parameters.
Example shell script
#!/bin/sh
java -jar yourJar.jar -Dfile.encoding=UTF-8 "$@"
For windows batch files have a look at http://www.computerhope.com/batch.htm
精彩评论