我有以下功能,它解密一个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 文件,而是应该将其写入标准输出。
最佳答案
PrintStream (stdout 的类)有一个 write 方法,可以调用该方法将 byte[] 写入 stdout。
关于java - 将字节流输出到标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12150473/