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]);
}
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());
}