Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Directory chooser/File system browser

  Asked By: Donna    Date: Sep 05    Category: Java    Views: 2421
  

I need an html-based directory chooser which should have access to the file system.
For now we can't use JSF, we can't use applet
(jfileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)),
there is no way in struts taglibs or JSP because of security concerns, I couldn't
find any component for it on internet.
So I mixed a recursive function for browsing the file system and struts layout
MenuComponent to create a tree view component as the following:

The following snippet comes in action



menu = new MenuComponent();
roots= File.listRoots();
menu.setName("treeview");
dirProcessor(roots,menu);
LayoutUtils.addMenuIntoSession(request, menu);
//--------------------

And here is the recursive method:

File[] children;
FileFilter fileFilter;
File dir;


fileFilter = new FileFilter(){
public boolean accept(File file){
return file.isDirectory();
}
} ;

if(list!=null){

for(int i=1;i<list.length;i++){

MenuComponent child = new MenuComponent();
child.setTitle(list[i].getName());
parent.addMenuComponent(child);


dir = new File(""+list[i]);

children = dir.listFiles(fileFilter);
if(children!=null){
for(int j=0;j<children.length;j++){


dirProcessor(children[j].listFiles(fileFilter),child) ;
}


}
}
}

It works correctly, but the recursive call is SO slow! It takes a very long time to process all the nested directories and the treeview displayed after 2 minutes,
Do you know a better way than this or any other way for speeding up?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Lela Lynch     Answered On: Sep 05

I have two comments:

1) Do you think that MenuComponent could cause some problem? Remove MenuComponet class and objects, and instead make some system.out.print when you want to create  and add child to this object. May be MenuComponent is slow.
2) Reading all folders and subfolders at once and move them to presentation layer could cause problem not only on server but also in the client. If the menu  is displayed by javascripts, then the client should manage a huge array which contain name and other attributes of the menu. We had this problem in a project once and the performace problem was at the client. The client took 1-2 minutes to read all Javascript stuff. It is a good idea to read each folder content when user clicks on them. Please have a look at www.opencms.org. This is a content management tool that shows lots of files and folder. You can get some idea from it. May be Ajax framework can help you with this.

 
Answer #2    Answered By: Mark R     Answered On: Sep 05

You simply usee html tag : <input type="file" name="file" id="file"/>
and this could be your file browser  on the web.

 
Answer #3    Answered By: Jaime Bowman     Answered On: Sep 05

<input file>is a file  chooser, I need a directory  chooser,
The user must have the permission to navigate the hard drives and select a specific directory (not a file)
since it would be bad for web pages to browse hard drives it is a security  issue
so neither <input type="file"> nor <html:file> have this capability

 
Answer #4    Answered By: Brandon Tucker     Answered On: Sep 05

If your project's client is on windows OS you could use this script to open directory  :
open

 
Answer #5    Answered By: Al Allen     Answered On: Sep 05

easy just don't load all subfolders, load them on demand,
I mean when user clicks on one folder load contents of that directory  and display them.

 
Didn't find what you were looking for? Find more on Directory chooser/File system browser Or get search suggestion and latest updates.




Tagged: