I am saving a document to the network drive through SFTP server by using JSCH. In that I have a some method like this to save document which take two parameters inputStream and path 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");
So, In the above code I am directly using
1. new ByteArrayInputStream(message.getBytes())
instead of assigning it to some inputStream i.e
2 .InputStream in=new ByteArrayInputStream(message.getBytes());
If I do something like this I can close this Stream by doing is.close();. But How can close an Inputstream or outputStream when I directly use without defining it ? Or don’t I need to close this?
You do not need to close
ByteArrayInputStream– this is just an array, and not socket IO