【问题标题】:copyInputStreamToOutputStream(in, System.out) [duplicate]copyInputStreamToOutputStream(in, System.out) [重复]
【发布时间】:2017-02-14 15:45:29
【问题描述】:

我已通读 Android 的 Security with HTTPS and SSL 文档。我看到它一直在使用copyInputStreamToOutputStream(in, System.out);。这给了我

error: cannot find symbol method copyInputStreamToOutputStream(InputStream,PrintStream)

这是有问题的代码:

URL url = new URL("https://wikipedia.org");
URLConnection urlConnection = url.openConnection();
InputStream in = urlConnection.getInputStream();
copyInputStreamToOutputStream(in, System.out);

copyInputStreamToOutputStream是什么意思?

【问题讨论】:

  • 对我来说看起来像是一种将输入流复制到输出流的方法。他们似乎没有提供它,但它只有六行代码左右。

标签: java android


【解决方案1】:

Easy way to write contents of a Java InputStream to an OutputStream

来自 Apache 的 org.apache.commons.io.IOUtils 有一个方法叫做 copy(InputStream,OutputStream) 完全符合您的要求 为。

IOUtils.copy(in,out);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2020-11-13
    • 2013-02-15
    相关资源
    最近更新 更多