Java File convertInputStreamToString() Utility Method - Converts InputStream to a String.
Java File convertInputStreamToString() Utility Method - Converts InputStream to a String
/**
* Converts InputStream to a String
* @param in
* @return
* @throws IOException
*/
public static String convertInputStreamToString(final InputStream in ) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in .read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
/**
* Converts InputStream to a String
* @param in
* @return
* @throws IOException
*/
public static String convertInputStreamToString(final InputStream in ) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in .read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
}
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course