How do I change InputStream to String?

Asked 2 years ago, Updated 2 years ago, 110 views

I want to convert the java.io.InputStream object to String.

If InputStream contains textual data, I think we can change it to String What do I do?

p.s. Please let me know the simplest way to do it in the code below.

public String convertStreamToString(InputStream is) { // ??? }

string java io stream inputstream

2022-09-22 10:15

1 Answers

It's easy if you use IOUtils.
StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer, encoding); String theString = writer.toString(); If I do this or lower it, String theString = IOUtils.toString(inputStream, encoding);


2022-09-22 10:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.