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

可紊 提交于 2019-12-13 23:51:46

问题


This is a continuation of HTML tags are getting converted

When I try to the following

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

I am getting

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

How can I replace &lt; with <

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.


回答1:


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;","<");

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

byte[] bytes = str.getBytes();


来源:https://stackoverflow.com/questions/40816016/incompatible-types-found-class-java-lang-string-required-class-java-io-bytea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!