将一个字节流输出到标准输出

5
我有以下功能,可以解密一个base64文件并将其写入txt文件。但是,我想让它输出到stdout而不是写入文本文件。请问我们该如何实现?
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文件中,它应该将其写入stdout。

4
一般情况下,这将是 System.out.write - McDowell
我尝试在下面执行此操作,但仍无法得到正确的值while ((numBytes = is.read(bytes)) != -1) { //os.write(bytes, 0, numBytes); System.out.write(bytes); } - brooding_goat
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
5

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,