title: ftpClient.retrieveFileStream(filepath) returning null
body: <p>I have a folder and it has 3 files in ftp.For first file the bufferreader is reading successfully.But from second file InputStream is getting as null.Dont know what is the reason.</p>
  
  <p>My code is </p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
   import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.SocketException;
  import java.util.logging.Logger;
  
  import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPFile;
  import org.apache.commons.net.ftp.FTPReply;
  
  public class ExtractFile{
  
   public static void main(String args[]) {
  
   // get an ftpClient object
   FTPClient ftpClient = new FTPClient();
   FileOutputStream fos = null;
  
    try {
    // pass directory path on server to connect
    ftpClient.connect("XXXX");
  
    // pass username and password, returned true if authentication is
   // successful
    boolean login = ftpClient.login("XXXX", "XXXXX");
  
   if (login) {
  System.out.println("Connection established...");
  
  FTPFile[] files=ftpClient.listDirectories();
  for(int i=0;i&lt;files.length;i++){
  
  
      FTPFile file=files[i];
  
      BufferedReader reader = null;
      String firstLine = null;
  
      try {
  
          String currentline=null;
  
          listDirectory(ftpClient, ftpClient.printWorkingDirectory(), "", 0);
  
  
      } finally {
          if (reader != null) try { reader.close(); } catch (IOException logOrIgnore) {}
      }
  
  
  
  }
  
  
     boolean logout = ftpClient.logout();
     if (logout) {
      System.out.println("Connection close...");
      }
     } else {
     System.out.println("Connection fail...");
    }
  
    } catch (SocketException e) {
     e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
     try {
    ftpClient.disconnect();
    } catch (IOException e) {
    e.printStackTrace();
   }
  }
  }
   static void listDirectory(FTPClient ftpClient, String parentDir,
          String currentDir, int level) throws IOException {
      String dirToList = parentDir;
      if (!currentDir.equals("")) {
          dirToList += "/" + currentDir;
      }
  
      FTPFile[] subFiles = ftpClient.listFiles(dirToList);
  
      if (subFiles != null &amp;&amp; subFiles.length &gt; 0) {
          for (FTPFile aFile : subFiles) {
              String currentFileName = aFile.getName();
  
              if (currentFileName.equals(".")
                      || currentFileName.equals("..")) {
  
                  continue;
              }
              for (int i = 0; i &lt; level; i++) {
                  System.out.print("\t");
              }
              if (aFile.isDirectory()) {
                  System.out.println("[" + currentFileName + "]");
                  listDirectory(ftpClient, dirToList, currentFileName, level + 1);
              } else {
                  System.out.println(currentFileName);
                  String currentline=null;
                  BufferedReader reader = null;
                  String firstLine = null;
  
                  /*****here i am getting stream as null**********/
                  InputStream stream = ftpClient.retrieveFileStream(dirToList+"/"+currentFileName);                   
  
  
  
                  reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
                  String[] lines=new String[5];
                  int i=0;
  
                      //TODO 
  
                  while((currentline=reader.readLine())!=null){
                      lines[i]=currentline;
                      i++;
                          System.out.println(".."+currentline);
                  }
  
               }
  
          }
      }
    }
   }
  </code></pre>
  
  <p>Why i am getting InputStream as null from the second file??</p>