Jump to content

clockwork


Recommended Posts

I have this clock that I am making and was wondering if it was possible for java to randomly access any file, and open, that the user types in the pathing for. I am using this for the alarm portion of the clock so that an user can easily make a folder within one folder and then have the program open any music file located within it when the alarm goes off.

 

 

 

example:

 

Folder path was c:\desktop\blah

 

 

- Desktop -

blah
- hig
- file
- file
- fri
- file
- file
- die
- file
- file

Quote - Revenge is such a nasty thing that only breeds more vengeful souls, but in some situations revenge does not even need to be sought out, but only bided.

Link to comment
Share on other sites

package tests;

import java.io.*;
import java.util.Random;

public class Main {
   Random rg = new Random();
   public static void main(String[] args) {
       File f = new File("C:\\");
       Main main = new Main();
       main.getRandomFile(f);
   }

   public File getRandomFile(File file) {
       File[] files = file.listFiles();
       int number = rg.nextInt(files.length);
       if(files[number].isDirectory()){
           System.out.println(files[number].toString());
           return getRandomFile(files[number]);
       }
        else{
           System.out.println(files[number].toString());
           return files[number];
        }
   }
}

 

 

Something I threw together in a few seconds, ignore the System outs :)

ivo2pe7.gif

http://www.tip.it/runescape/?herb

^^ A herblore cost/xp calculator. Any feedback would be greatly appreciated. Cleaning herbs has the values switched at the moment, but the fix has been submitted.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.