aspose file tools*
The moose likes Beginning Java and the fly likes Can I select and put multiple file names in to an array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can I select and put multiple file names in to an array?" Watch "Can I select and put multiple file names in to an array?" New topic
Author

Can I select and put multiple file names in to an array?

Maduranga Liyanage
Ranch Hand

Joined: May 25, 2005
Posts: 124
Hello,

I would really appreciate if somebody could tell me if it is possible to do this and an approach to do it.

What I basically want to do is to open up a file-browse dialog box. These file-browsing boxes usually let you select only one file. What I want to do is to open up a file-browse box, and let the user choose 'multiple' files in a folder. And then I want to store these selected file names in an Arraylist. That it.

Is it possible for me do that?
Any ideas are greatly appreciated.

Cheers.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

JFileChooser can be set to allow multiple files to be chosen/selected via the setMultiSelectionEnabled(boolean b) method. If this is set to true, then the user can select multiple files. You can then use the getSelectedFiles() method to get an array of files the user selected.

If you want those in a List, use the Arrays.asList(T... a) method to convert to a java.util.List:



For more information on how to use File Choosers in Swing, see the Java Tutorial lesson How to Use File Choosers
[ July 27, 2008: Message edited by: Mark Vedder ]
Maduranga Liyanage
Ranch Hand

Joined: May 25, 2005
Posts: 124
Awesome!
Thanks a million Mark. Looks like Java has a method for everything
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I select and put multiple file names in to an array?