不兼容的类型;找到:类java.lang.String,必需:类java.io.ByteArrayOutputStream [英] Incompatible types; found: class java.lang.String, required: class java.io.ByteArrayOutputStream

查看:888
本文介绍了不兼容的类型;找到:类java.lang.String,必需:类java.io.ByteArrayOutputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 HTML标签正在转换的延续

当我尝试以下操作

 ByteArrayOutputStream stream= new ByteArrayOutputStream();
 stream= stream.toString().replaceAll("&lt;","<");

我正在


个不兼容的类型;找到:类java.lang.String,必需:类java.io.ByteArrayOutputStream

incompatible types; found: class java.lang.String, required: class java.io.ByteArrayOutputStream

如何替换 & lt; <

在另一个问题中, HTML标签正在转换,由于这个原因,在我打印以打开HTML页面之前,我想转换< <如果它存在于流中。

As mentioned in the other question, my HTML tags are getting converted and due to this reason before I print to open the HTML page, I would like to convert < to < if it exist in the stream.

请合理地说出拒绝投票的原因,而不是为此而拒绝投票。

Kindly suggest the reason for down voting as it makes sense rather than down voting for the sake of it.

推荐答案

您正在尝试分配 replaceAll (一个 String )到 stream ,一个 ByteArrayOutputStream 。我认为您的意思是只创建一个类型为 String 的新变量:

You're trying to assign the result of replaceAll (a String) to stream, a ByteArrayOutputStream. I think you mean to just create a new variable of type String:

ByteArrayOutputStream stream= new ByteArrayOutputStream();
String str = stream.toString().replaceAll("&lt;","<");

然后可以将 String 转换为字节数组,使用 getBytes

You can then convert the String to a byte array, using getBytes:

byte[] bytes = str.getBytes();

这篇关于不兼容的类型;找到:类java.lang.String,必需:类java.io.ByteArrayOutputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆