Results 1 to 2 of 2
  1. #1
    ravjot28 is offline Member
    Join Date
    Jun 2008
    Posts
    87
    Rep Power
    0

    Default Selecting Files in a folder

    How can i choose a random file from a bunch of files present in a single folder.

    Eg:

    Folder : New Folder

    Files : 1.txt 2.txt 3.txt 4.txt

    Now i want to select any random file.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by ravjot28 View Post
    How can i choose a random file from a bunch of files present in a single folder.

    Eg:

    Folder : New Folder

    Files : 1.txt 2.txt 3.txt 4.txt

    Now i want to select any random file.
    The File class has some fine methods that give you an array of files in a directory. Arrays have a 'length' member and the Random class can generate a random number between 0 and a maximum value (exclusive).

    kind regards,

    Jos

Similar Threads

  1. Replies: 2
    Last Post: 02-20-2009, 07:13 AM
  2. How To Place Three Files In A Folder
    By ramesh.8189 in forum AWT / Swing
    Replies: 4
    Last Post: 02-12-2009, 07:59 AM
  3. Placing Files In Folder
    By ramesh.8189 in forum New To Java
    Replies: 0
    Last Post: 02-06-2009, 12:36 PM
  4. Replies: 0
    Last Post: 10-06-2008, 03:42 PM
  5. iteration on huge amount of files in a folder
    By tshaked in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •