gpt4 book ai didi

java - 使用 stringwriter 遇到编码问题

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:51 25 4
gpt4 key购买 nike

我用过

StringWriter writer = new StringWriter();
request.setCharacterEncoding("ISO-8859-1");
response.setContentType("text/html;charset=ISO-8859-1");
pw =response.getWriter();
IOUtils.copy(sImage, writer);
theString = writer.toString();
pw.write(theString);
pw.flush();

在客户端浏览器中,输出为

ÿþ<�h�t�m�l�x�m�l�n�s�:�v�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�of�t�-�c�o�m�:�v�m�l�"��x�m�l�n�s�:�o�=�"u�r �n�:�s�c�h�e�m�a�s-�m�i�c�o�f�t�-�c�o�m�:�of�f�i�e�:�of�f�i�c�e"��x�m�l�n�s�:�w�=�"�u�r�n�:�s�c�h�e�m�s�-� m�i�c�r�s�f�t�-�c�o�m�:�f�i�c�e�:�w�o�r�d�"��x�m�l�n�s�:�x�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�s�f�t�-�c�m �:�off�ic�e�:�x�c�e�l�"��x�m�l�n�s�:�p�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�of�t�-�c�o�m�:�of�fi�c�:�p�ow� e�r�p�i�nt�"��x�m�l�n�s�:�a�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�of�t�-�c�o�m�:�of�f�ic�e�:�a�c�e�s�"� �

如果你们中有人知道这一点,我该如何解决这个问题

最佳答案

尝试使用这个:

response.setContentType("text/html; charset=UTF-16LE");

当然,它不会使您的文本成为 ISO-8859-1,但是,现在大多数浏览器支持 UTF-16 都没有问题。

关于java - 使用 stringwriter 遇到编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4151174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com