user5555231
user5555231

Reputation: 77

Java CSV encoding

I have a CSV file and i have a problem with number formats, in my java code the double's have Locale loc = new Locale("hu", "HU"); format so in the program looks like 1 401,1 but in CSV it looks like 1Â 401,1 How can I set encoding? I'm using javacsv library

String outputFile = Calc.tf_file.getText();         
boolean alreadyExists = new File(outputFile).exists();

        try {

            CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ';');


            if (!alreadyExists)
            {
                csvOutput.write("Point");
                csvOutput.write("Price");
                csvOutput.endRecord();
            }


                        for (int i = 0; i < Calc.number_list.size(); i++) {                       
                        csvOutput.write(Calc.point_list.get(i));
                        csvOutput.write(Calc.number_list.get(i));
                        csvOutput.endRecord();
                    }


            csvOutput.close();

Upvotes: 1

Views: 942

Answers (1)

user5555231
user5555231

Reputation: 77

Change:

CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ';');

To:

CsvWriter csvOutput = new CsvWriter(outputFile, ';', Charset.forName("Cp1250"));

Upvotes: 1

Related Questions