如何关闭InputStream未定义但直接在方法中使用的Inputstream?

时间:2013-01-08 07:13:36

标签: java inputstream outputstream jsch

我使用JSCH通过SFTP服务器将文档保存到网络驱动器。我有一个像这样的方法来保存文件,其中包含两个参数inputStreampath to save the stream into a file which is a string.

String message="I am saving this file to the shared drive";
channelSftp.put(new ByteArrayInputStream(message.getBytes()),pathFromChannel+"/"+"file.txt");

所以,在上面的代码中我直接使用

1. new ByteArrayInputStream(message.getBytes())

而不是将其分配给某个inputStream,即

2 .InputStream in=new ByteArrayInputStream(message.getBytes());

如果我这样做,我可以通过is.close();关闭此流。但是,当我直接使用而不定义它时,如何关闭InputstreamoutputStream?或者我不需要关闭它?

1 个答案:

答案 0 :(得分:1)

您不需要关闭ByteArrayInputStream - 这只是一个数组,而不是套接字IO