2012-11-08 29 views
1

我想用阿拉伯语创建CSV文件列,我正在使用资源包从属性文件中获取值,并且能够在阿拉伯文中获得值,但创建文件后列名显示为“?? ???????????”而不是阿拉伯语。请帮我解决这个问题。如何用阿拉伯语创建csv文件?

我使用下面的代码:

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; 
    } 
} 
+2

请张贴您的代码。 – logoff

+0

该文件正确enconaded但阿拉伯语言不显示... –

回答

2

如果在内容类型使用CP1256,你必须使用相同的时创建的文件与java.io.PrintStream

我建议:

OutputStream out = response.getOutputStream(); 
PrintStream ps = new PrintStream(out, true, "CP1256"); 
ps.println(downloadStr); 
ps.close(); 

It's not necessary to flush and close out变量。

+0

我已经发布的代码,我必须添加? –

+0

请编辑您的问题以发布Java代码。我将在我的答案中编辑它以向你展示 – Aubin

+0

我试过那个,但编译时错误即将到来,错误是 - >构造函数PrintWriter(OutputStream,String)未定义。 –