问题
This is a continuation of HTML tags are getting converted
When I try to the following
ByteArrayOutputStream stream= new ByteArrayOutputStream();
stream= stream.toString().replaceAll("<","<");
I am getting
incompatible types; found: class java.lang.String, required: class java.io.ByteArrayOutputStream
How can I replace <
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("<","<");
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