How to read 'List separator' from OS in Java?

前端 未结 7 2158
我寻月下人不归
我寻月下人不归 2020-12-20 16:33

I am writing a CSV exporter in Java that should respect the user\'s custom settings, especially the \"List separator\" to use as a delimiter.

In Windows, one can set

7条回答
  •  醉话见心
    2020-12-20 17:13

    I faced the same problem and also found out that the only proper solution is to provide a way to the user to specify the "delimiter of choice".

    However, if that is not possible, as it was in my case, the closest I could get to cross-platfrom, cross-locale support is the following:

    • guess the separators you need to use using DecimalFormatSymbols
    • add a line at the beginning of the CSV containing, for example "sep=," (without quotes), this should specify the list separator you've just guessed

    This will, at least in most cases (the cases I have tested), force Excel to use that delimiter, even if you "guessed wrong" and will provide at least a little bit more compatibility.

提交回复
热议问题