如何在Java中添加UTF-8 BOM? [英] How to add a UTF-8 BOM in Java?
本文介绍了如何在Java中添加UTF-8 BOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java存储过程,该存储过程使用Resultset
对象从表中获取记录并创建CS Vfile.
I have a Java stored procedure which fetches record from the table using Resultset
object and creates a CS Vfile.
BLOB retBLOB = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION);
retBLOB.open(BLOB.MODE_READWRITE);
OutputStream bOut = retBLOB.setBinaryStream(0L);
ZipOutputStream zipOut = new ZipOutputStream(bOut);
PrintStream out = new PrintStream(zipOut,false,"UTF-8");
out.write('\ufeff');
out.flush();
zipOut.putNextEntry(new ZipEntry("filename.csv"));
while (rs.next()){
out.print("\"" + rs.getString(i) + "\"");
out.print(",");
}
out.flush();
zipOut.closeEntry();
zipOut.close();
retBLOB.close();
return retBLOB;
但是生成的CSV文件没有显示正确的德语字符. Oracle数据库的NLS_CHARACTERSET
值也为UTF8.
But the generated CSV file doesn't show the correct German character. Oracle database also has a NLS_CHARACTERSET
value of UTF8.
请提出建议.
推荐答案
要使用UTF-8编写BOM,您需要PrintStream.print()
,而不是PrintStream.write()
.
To write a BOM in UTF-8 you need PrintStream.print()
, not PrintStream.write()
.
此外,如果您想在csv
文件中包含BOM表,我想您需要在putNextEntry()
之后打印BOM表.
Also if you want to have BOM in your csv
file, I guess you need to print a BOM after putNextEntry()
.
这篇关于如何在Java中添加UTF-8 BOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文