read files from directory


2005-08-01 01:52:36 AM
jbuilder19
Hi. I'm trying to get all the files from a directory.
I get the absolute name of the directory using the next:
JFileChooser chooser = new JFileChooser();
dirLocal = chooser.getSelectedFile().getAbsolutePath());
The problem is that the name needs 2 backslash and getAbsolutePath()
doesn't work like that.
How Can I fix this????
File myFile = new File("F:\\myDirectory"); //This must be variable
File[] allFiles = myFile.listFiles();
int i, j, k;
System.out.println("Directoy: " + dirLocal);
k = 0;
for (i = 0; i < allFiles.length; i++) {
if (allFiles[i].isFile()) {
j = (new Long(allFiles[i].length())).intValue();
if (j <= MAX_TAM) {
Vector row = new Vector(2);
row.addElement(allFiles[i]);
row.addElement(new Integer(3));
model.insertRow(k++, row);
}
}
}