-
June 8th, 2009, 10:48 PM
#1
List all the files and subdirectory in jtable
I had faced the problem where I cannot list the content in jtable..as I would like to list out all the files, subdirectory and its last modified in that table… help…
// gets the sub files of a folder
public ArrayList<File> getSubs(File dest) {
File[] subfiles = dest.listFiles();
ArrayList<File> subFolders = new ArrayList<File>();
// if subfiles is null, it means that listFiles() didnt return anything,
// so we are dealing with a file, not a folder
if (subfiles != null)
// all teh contents of the folder are added to the array list
for (int i = 0; i < subfiles.length; i++) {
subFolders.add(subfiles[i]);
}
else
// otherwise we jist add the file to the list
subFolders.add(dest);
return subFolders;
}
public Object[][] getFileStats(File folder){
ArrayList<File> folderList = new ArrayList<File>();
// first we add all the contents of the folder that we want to scan to
// the folderList
folderList.addAll(getSubs(folder));
//File[] list1= folder.listFiles();
Object[][] results = new Object[folderList.size()][header.length];
for (int i = 0; i < folderList.size(); i++) {
long modTime = folderList.get(i).lastModified();
Date d = new Date(modTime);
if (folderList.get(i).isDirectory()) {
// if its a directory, we get all its subfolders/files and add them to the folderList
folderList.addAll(getSubs(folderList.get(i)));
results[i][0]= folderList.get(i);
results[i][1]= d.toString();
}
}
return results;
}
-
June 9th, 2009, 07:09 AM
#2
Re: List all the files and subdirectory in jtable
When posting code, please put it between CODE tags so it remains readable.
I can't see JTable used anywhere in that code - exactly what is the problem?
The sooner you start to code, the longer the program will take...
R. Carlson
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|