Hello everyone.
I am new to this, so take it easy on me
I was trying to learn how to mess with files, and I decided to write a program that will search a specified directory for a specified file extension. so if i wanted to search C:\!files\ for .mp3 files, it returns a printed list of the files with that extension. well, now that i can do that, what do i do with the files? i have winamp on my computer, and i would like to play these mp3 files like a playlist, but have no way to go about executing an mp3 file, or even opening winamp with
java. anyone have any ideas? what classes/methods/etc i should use?
CODE:
import java.io.*;
public class Search {
public static void main(
String args[]) throws java.io.IOException {
// create a buffered reader "in" to store a string that you input
// from the keyboard.
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the directory for search...");
// reading in the string typed from the keyboard, and stored as String sBlah
String sBlah = in.readLine();
System.out.println("String in = " + sBlah);
File dir = new File(sBlah);
System.out.println("dir.isDirectory()=" + dir.isDirectory());
if(dir.isDirectory() == true) {
System.out.println("Enter the file extension you would like to search for.");
System.out.println("Avoid * and quotations.");
final String sExtension = in.readLine();
in.close();
String[] sPlayList = dir.list(new FilenameFilter() {
public boolean accept(File f, String s)
{
return(s.endsWith(sExtension));
} // end accept
});
System.out.println("Listing files....");
for (int i = 0; i < sPlayList.length; i++)
{
System.out.println(sPlayList[i]);
} // end for
if(sPlayList.length == 0) {
System.out.println("There aren't any Mp3's in this directory dummy!");
} // end if
} // end if
else
{
System.out.println("The directory that you entered does not exist...Typical..");
} // end else
} // end main
} // end class Search
Mike O'Brien