This discussion is archived
2 Replies Latest reply: Oct 22, 2012 9:28 AM by DrClap RSS

Create CSV with Arabic text in java

chesplay Newbie
Currently Being Moderated
I am trying to create a CSV file with Arabic characters in it, but the file shows some junk characters instead of Arabic.

The first code I tried:

PrintWriter pw = new PrintWriter("C:\\WriteTest.CSV","UTF-8");
pw.println("a csv file and now a new line is going to come");
pw.print(",");
pw.println("حتاليبلات-حخهعغفق");
pw.print(",");
pw.print("Hey");
Output:

a csv file and now a new line is going to come
,Øتاليبلات-ØخهعغÙÙ‚
Hey
My second attempt:

FileOutputStream fos = new FileOutputStream("C:\\WriteTest1.csv");
String in = new String("خثتيهث", "UTF8");
fos.write(in.getBytes("UTF-8"));
Output:

متانتاتن
Please suggest how I can create a CSV with Arabic characters in it. My code works well when I change the file from CSV to txt.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points