Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

FTPClient class listFiles() method is not returning list of files

  Asked By: Nisha    Date: Jun 07    Category: Java    Views: 1520
  

In FTPClient class listFiles() method is not returning list of files
it doesnot give any compiletime error but on execution gives null
pointer exception.

Actually i want to manipulate files based on their size.

piece of code is:

FTPFile files[] = ftc.listFiles();
for(int i=0;i<files.length;i++)
{
FTPFile file = files[i];
System.out.println("File Size:"+file.getSize());
if((name.endsWith("."))||(name.endsWith(".."))){}
else{
if(name.indexOf(".")!=-1)
{
if(name.endsWith(type))
{
if(files[i].getSize()<size)
FileOutputStream fos = new FileOutputStream(new File
("c:\\download\\",name));
ftc.retrieveFile(name,fos);
}
}
}
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Perdita Lopez     Answered On: Jun 07

You might want to declare and initialise files[] first and then use it. That way
we can make sure there was a memory allocation. I guess thats the problem in ur
case

 




Tagged: