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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 中添加 UTF-8 BOM?
基础教程推荐
- 将 double 转换为 Int,向下舍入 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
