Http://files.cnblogs.com/files/xjyggd/html5music.rar
Import Java.io.File;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import Java.util.Map;
public class Directorytest {
private static arraylist<string> filelist = new arraylist<string> ();
private static map<string, string> Filemap = new hashmap<string, string> ();
public static void Main (string[] args) throws Exception {
String FilePath = "G://music//mp3";
GetFiles (FilePath, "MP3");
StringBuilder StringBuilder = new StringBuilder ();
for (String strfile:filelist)
{
string[] Strfilesplit = Strfile.split ("\\\\");
String strFileName = strfilesplit[strfilesplit.length-1];
System.out.println (strFileName);
if (stringbuilder.length () > 0)
{
Stringbuilder.append (",");
}
Stringbuilder.append ("{name: '" + strFileName + "', Author: ', url: '" + strfile.replace ("\ \", "\\\\") + "'}");
}
System.out.println (Stringbuilder.tostring ());
}
/*
* Recursively get all the directories and their files under a certain path
*/
static void GetFiles (string filePath, string pattern) {
File root = new file (FilePath);
file[] files = root.listfiles ();
for (File file:files) {
if (File.isdirectory ()) {
/*
* Recursive invocation
*/
GetFiles (File.getabsolutepath (), pattern);
Filelist.add (File.getabsolutepath ());
System.out.println ("Show" +filepath+ "all subdirectories and their files" +file.getabsolutepath ());
}
Else
{
System.out.println ("Show" +filepath+ "All Subdirectories" +file.getabsolutepath ());
if (File.getname (). Contains (pattern))
{
Filemap.put (File.getname (), File.getabsolutepath ());
Filelist.add (File.getabsolutepath ());
System.out.println (File.getname () + "" + File.getabsolutepath ());
}
}
}
}
}
[Turn]HTML5 music player