Read InputStream with ByteArrayOutputStream
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
class Main {
public static String inputStream2String(InputStream inputStream) throws IOException{
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
while((bytesRead = inputStream.read(buffer)) != -1){
outputStream.write(buffer, 0, bytesRead);
}
return outputStream.toString("US-ASCII");
}
}
Related examples in the same category