【问题标题】:Output a byte stream to stdout将字节流输出到标准输出
【发布时间】:2012-08-22 10:37:00
【问题描述】:

我有以下函数,它解密 base64 文件并将其写入 txt 文件。但是,我希望它输出到标准输出,而不是写入文本文件。您能否建议我们如何做到这一点

CipherOutputStream cos = new CipherOutputStream(os, cipher);
    doCopy(is, cos);

}

public static void doCopy(InputStream is, OutputStream os) throws IOException {
    byte[] bytes = new byte[64];
    int numBytes;
    while ((numBytes = is.read(bytes)) != -1) {
        os.write(bytes, 0, numBytes);
    }

因此,os.write 不应将流写入 txt 文件,而应将其写入标准输出。

【问题讨论】:

  • 这通常是System.out.write
  • 我尝试在下面这样做,但它仍然不会产生正确的值 while ((numBytes = is.read(bytes)) != -1) { //os.write(bytes, 0, 字节数); System.out.write(字节); }

标签: java base64 stdout encryption


【解决方案1】:

PrintStream(stdout 类)有一个 write 方法,可以调用该方法将 byte[] 写入 stdout。

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2012-12-15
    • 2013-05-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多