0

I have a hashmap containing a key and some values, such as:

final Map<String, String> map = new HashMap<>();
{
    map.put("01", "Example – Description");
    map.put("02", "Example – Description")
}

The value, description, in the hashmap contains a hyphen and when outputting to a CSV file it isn't being displayed correctly and instead shows 'x96'. I understand there is some encoding here that needs to be done - UTF-8?

My question is, how do you do this for a hashmap?

I am accessing these values in a method like this:

add[0] = updateSomething[0] + " " + map.get(e.getKey());
Porkball21
  • 125
  • 1
  • 1
  • 8

1 Answers1

0

To force UTF-8, specify the JVM file encoding using:

java -Dfile.encoding=UTF-8 … com.x.Main

See Setting the default Java character encoding?

After you've done that, make sure you are opening the CSV with UTF-8 encoding as well.

See setting a UTF-8 in java and csv file

Community
  • 1
  • 1
jawnaphin
  • 16
  • 3