exception while reading a directory

hi,

i got a problem , i have a list of 2000 files in a directory and i haev to read it and process it,

am using file class to read as a directory , but the following code shows null pointer exception,

can anybody help me,

File database =new File("c:/gunasekp/Pdbfile/grepdatabase");

String datafiles[] = database.list();

for (int i = 0; i < datafiles.length; i++){

System.out.println("processing file: " + database.getAbsolutePath() +"/" + datafiles[0]);

}

[743 byte] By [prasadgunasa] at [2007-11-27 8:51:59]
# 1

if you get a null pointer exception here your file "database" doesn't exist or isn't a directory. Check for existance and directory before you call the list method like:

File database = new File("c:/gunasekp/Pdbfile/grepdatabase");

if (database.exists() && database.isDirectory())

{

String datafiles[] = database.list();

for (int i = 0; i < datafiles.length; i++)

{

System.out.println("processing file: " + database.getAbsolutePath() +

"/" + datafiles[0]);

}

}

else

{

System.out.println("Database exists: "+database.exists()+"\nDatabase is Directory: "+database.isDirectory());

}

marco@dea at 2007-7-12 21:06:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Check the return value of database.list();
AnanSmritia at 2007-7-12 21:06:33 > top of Java-index,Java Essentials,Java Programming...
# 3
This path not exists and the database.list() is returning null .so, datafiles.length is throwing NullPonterException .Use a valid path and get certified that the file.exists() returns trueCya.
pbulgarellia at 2007-7-12 21:06:33 > top of Java-index,Java Essentials,Java Programming...