本文介绍了如何在java中添加UTF-8 BOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Java存储过程,它使用Resultset对象从表中获取记录并创建一个csv文件。
I have a Java stored procedure which fetches record from the table using Resultset object and creates a csv file.
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,我想你需要打印一个BOM后 putNextEntry()
。
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!