We have modified the application to support Non-Latin characters (Chinese & Thai) but we faced some issues in writing to CSV and resolved using below approach.
String line = "שלום, hello, привет";
OutputStream os = new FileOutputStream("c:/temp/j.csv");
os.write(239);
os.write(187);
os.write(191);
PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
w.print(line);
w.flush();
w.close();
The above one works but we are facing some other issues listed below.
We opened a CSV file using below code and it was working fine.
File file = new File(System.getProperty(TEMP_DIR_SYSPROP), filename); FileUtils.writeByteArrayToFile(file, bytes); Desktop.getDesktop().open(file);
But when it is written with UTF-8 we are facing below issue with excel.
NonLatin.csv is locked for editing by another user. Open 'Read-Only' or click 'Notify' to open and receive notification when the document is no longer in use. Or Cancel out.
- Double quotes is getting for few entries in csv which shows as different content when filter is applied.
Please suggest if there is any limitation with above approach (UTF-8) or is there any work around to handle this.