我想确保我的书面CSV文件使用UTF-8进行编码:
public StreamResource getExportDataAsCsv() {
return new StreamResource(new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
List<Object[]> exportData = getExportData();
StringBuffer buffer = new StringBuffer();
buffer.append(someData);
byte[] bytes = buffer.toString().getBytes();
return new ByteArrayInputStream(bytes);
}
}, "MyExport.csv");
}
不幸的是,找到的方法/方法不适合我的界面。有什么想法吗?
答案 0 :(得分:1)
buffer.toString().getBytes("UTF-8");