Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome!
Thanks a million Mark. Looks like Java has a method for everything
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic