• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome!
Thanks a million Mark. Looks like Java has a method for everything
 
reply
    Bookmark Topic Watch Topic
  • New Topic