一般做法是启动两个单独的线程来读取信息
if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { inputStream = httpURLConnection.getInputStream(); } else { inputStream = httpURLConnection.getErrorStream(); System.out.println("error++++++++++"); } FileOutputStream fileOutputStream = null; File downloadFile; File sd...
从启动其他程序的Java进程看,已启动的其他程序输出就是一个普通的输入流,可以通过getInputStream()和getErrorStream来获取。 对于一般输出文本的进程来说,可以将InputStream封装成BufferedReader,然后就可以一行一行的对进程的标准输出进行处理。 4、举例 (1)Runtime.exec() import java.io.BufferedReader;import java.i...
HttpURLConnection的getErrorStream方法用于在HTTP请求失败时获取错误响应的数据流。如果HTTP请求返回了一个4xx或5xx状态码,即请求失败或服务器错误,getErrorStream将返回一个InputStream,其中包含服务器返回的错误响应体。 2. 阐述何时应该使用getErrorStream方法 当HttpURLConnection对象的getResponseCode方法返回一个表示错误的...
package com.wenjiangs; import java.io.InputStream; public class ProcessDemo { public static void main(String[] args) { try { // create a new process System.out.println("Creating Process..."); Process p = Runtime.getRuntime().exec("notepad.exe"); // get the error stream of the pr...
responseInputStream = httpsURLConnection.getInputStream(); }else{ responseInputStream = httpsURLConnection.getErrorStream(); } BufferedReader responseReader =newBufferedReader(newInputStreamReader(responseInputStream, StandardCharsets.UTF_8)); StringBuilder responseStringBuffer =newStringBuilder(); ...
public InputStream getErrorStream() { return process.getErrorStream(); } 代码示例来源:origin: gocd/gocd private void close(Process p) { try { IOUtils.closeQuietly(p.getInputStream()); IOUtils.closeQuietly(p.getOutputStream()); IOUtils.closeQuietly(p.getErrorStream()); } finally { if (p ...
getErrorStream() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error. getErrorStream() method does not throw an exception at the time of returning input stream.Syntax...
Pump.stream2stream(inputStream, xfilter.getInputStream())ifself.__use_stdout:# outputasserttrace("Pumping %s stdout to outputStream"% self.__name) Pump.stream2stream(xfilter.getOutputStream(), outputStream)ifself.__separate_stderr:asserttrace("Handling %s stderr"% self.__name) ...
in = con.getInputStream(); } ByteArrayOutputStream result =newByteArrayOutputStream();byte[] buffer =newbyte[1024];intlength;while((length = in.read(buffer)) != -1) { result.write(buffer,0, length); } response.output = result.toString(); ...