I am trying to create CSV file column in Arabic language, I am using resource bundle to get the value from properties file and it is able to get value in Arabic but after creation of file the column name is displaying like “?????????????” instead of Arabic. Please help me to resolve this problem.
I am using below code:
public static void downloadCSVForReconcilationData(String downloadStr,HttpServletResponse response,String reportName) throws IOException{
//response.setHeader("Content-Disposition", "inline;filename=\""+"BillingTrxReport.csv"+"\"");
response.setContentType ("application/x-csv");
response.setHeader("Content-Disposition","attachment; filename=\""+reportName+".csv"+"\";");
//response.setHeader("application/vnd.ms-excel;charset=Cp1256","attachment; filename=\""+reportName+".csv"+"\";");// khushwant Patidar
response.setContentType("application/vnd.ms-excel;charset=Cp1256");// khushwant Patidar
response.setContentLength((int) downloadStr.length());
try{
OutputStream out = response.getOutputStream();
PrintWriter pw = new PrintWriter(out);
BufferedWriter bufw=new BufferedWriter(pw);
//BufferedOutputStream outBuf = new BufferedOutputStream(out);
bufw.write(downloadStr);
bufw.close();
pw.close();
out.flush();
out.close();
}catch(IOException ioe){
ioe.printStackTrace();
throw ioe;
}
}
If you use CP1256 in content-type you must use the same when creation the file with java.io.PrintStream.
I suggest:
It’s not necessary to flush and close the out variable.