how to read files in whole directory

hi everybosy i have got a directory called grepdatabase in the following path

/users/zer/gd.

it has 3000 files in it.i have to read each file and do soem process and write it into another file.

but with the following code it says, directorydoesnot exists.but i have the directory,with all the files in it.

File database =new File("c:/Domain/nbi.bbsrc.ac.uk/Users/zer/gd");

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

}

can anyone help me how to read multiple files...

[1318 byte] By [prasadgunasa] at [2007-11-27 9:38:14]
# 1
Aren't you window users supposed to use the \ character?
ChristopherAngela at 2007-7-12 23:11:15 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

Just couple of small mistakes....

1. use escape sequence,

2. iterate through i in the loop and also use the index 'i' to print those file path.

File database = new File("c:\\Domain\\nbi.bbsrc.ac.uk\\Users\\zer\\gd");

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);

}

} else {

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

}

Cheers.

Message was edited by:

jini4java

jini4javaa at 2007-7-12 23:11:15 > top of Java-index,Java Essentials,Java Programming...
# 3
hi ,i am unix user so i cant use \\,i suppose and the problem is i have a directory with lots of fiels already,but the code is not recognisisng those directory and files ,though i have given the same path.i cant find what the problem is.
prasadgunasa at 2007-7-12 23:11:15 > top of Java-index,Java Essentials,Java Programming...
# 4

ur code can be little modified as follows to make it work flawlessly

File database = new File("c:/Domain/nbi.bbsrc.ac.uk/Users/zer/gd");

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

//String datafiles[] = database.list();

//Instead use file list here

File[] datafiles = database.listFiles();

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

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

//"/" + datafiles[0]);

System.out.println("processing file: " + datafiles[i].getName());

}

} else {

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

}

BR

mohammedsajida at 2007-7-12 23:11:15 > top of Java-index,Java Essentials,Java Programming...