My requirement is to get list of files of required file extension from different directories and while getting the files itself i should get the input stream and do some processing....
I am trying to get the list of files with required file extension, then I am trying to get input stream from all the selected files in that list.
For the first iteration, i am getting the required files and also i am getting the stream for one file but for the next file, i get a null pointer exception. I am also unable to get the list of files from the second iteration

The count of files is shown as 3 and the first file in the 'mydirectory' is read correctly but when it tries to read the second file it says null pointer exception .... also, after i read the stream using retrieveFileStream method, if i try to print current working directory, it gives null value but says it is still connected....

Please let me know if i have some bugs in my code....
The only workaround for me was to connect to the ftp location for every input stream read which is not a good thing to do....

There are two optimizations that I would suggest.
First, I would recommend using FTPClient.listNames. This will return an array of Strings.
Secondly, use IOUtils.readFully(inputStream) that returns a String representation of contents in the file.

Now coming to the problem in hand, I assume you are executing these commands in locl passive mode. include this in your code above ftp.retreiveFileStream.