title: Java InputStreams not closing or letting go of file
body: <p>The FileInputStream is not closing when using close().  Wwhen the loop starts back up any files not SFTPd over (due to timeout from server) are inaccessible because it's still holding on the file from the previous loop.  What am I doing wrong when closing the FileInputStream?</p>
  
  <p>Error Text:
  java.nio.file.FileSystemException: [Path to File] -> [Path to File]: The process cannot access the file because it is being used by another process.</p>
  
  <p>Execptions:
  java.net.ConnectException: Connection timed out: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:589)
      at org.apache.commons.net.ftp.FTPClient.<em>openDataConnection</em>(FTPClient.java:920)
      at org.apache.commons.net.ftp.FTPSClient.<em>openDataConnection</em>(FTPSClient.java:627)
      at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:653)
      at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:639)
      at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:2030)
      at alliedftp.AlliedFtp.putFiles(AlliedFtp.java:73)
      at alliedftp.AlliedFtp.main(AlliedFtp.java:37)</p>
  
  <p>java.nio.file.FileSystemException: [Path to File] -> [Path to File]: The process cannot access the file because it is being used by another process.</p>
  
  <pre><code>at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
  at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
  at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:387)
  at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
  at java.nio.file.Files.move(Files.java:1395)
  at alliedftp.AlliedFtp.putFiles(AlliedFtp.java:77)
  at alliedftp.AlliedFtp.main(AlliedFtp.java:37)
  
  private static void putFiles(String filePath) {
          AlliedFtp.setPath(filePath);
          FTPSClient client = new FTPSClient();
          String today = new SimpleDateFormat("MMddyyyy").format(new Date()) + "_";
  while(true) {
              try {
                 ArrayList&lt;FileInputStream&gt; list = AlliedFtp.setFileInputStreams(new File(path));
                 ArrayList&lt;File&gt; listNames = AlliedFtp.setFileNames(new File(path));
                 int fileStreamsSize = list.size();
                 int fileNamesSize   = listNames.size();                    
                 // Connect to remote host
                 client.connect(ftpServer);
                 // Login
                 if(!client.login(ftpUser, ftpPass)) {
                     client.logout();
                     System.out.println("Login Error");
                 } 
                 // Enter passive mode
                 //client.setBufferSize(1024000);
                 client.enterLocalPassiveMode();
                 client.setFileType(FTP.BINARY_FILE_TYPE);
                 // SFTP Files
                 for(int i = 0; i &lt; fileNamesSize; i++) {     
                      // SFTP files
                      if(client.storeFile(listNames.get(i).getName(), list.get(i))) {
                          // Close input stream
                          list.get(i).close();
                          // Move Files
                          Files.move(listNames.get(i).toPath(), Paths.get(path + File.separator + "Archive" + File.separator + today + listNames.get(i).getName()), StandardCopyOption.REPLACE_EXISTING);   
                      } else {
                          list.get(i).close();
                      }
                  }                                
                  // Log Out
                  client.logout();
                  client.disconnect();   
              } catch(IOException e) {
                  System.err.println(e);
              } 
              // Wait
              try {
                  TimeUnit.MINUTES.sleep(2);
              } catch(InterruptedException e) {
                  System.out.println(e);
              }  
          }  
      }
  </code></pre>