日期:2014-05-20  浏览次数:20849 次

手机文件遍历问题(内有简短代码)
功能   以一个文件名遍历手机所有根文件系统下的所以文件   列出同名文件  
简单的说就是   输入一个歌曲名   搜索本机所有文件中同名文件
入参是文件名  
返回一个Bean数组   每个对象包括文件名和路径
自己写了一个方法
不知道怎么继续了
public   LocalMusicBean[]   getCurList(String   curPath,   String   musicName)   {
LocalMusicBean[]   s   =   null;
try   {
FileConnection   fc   =   (FileConnection)   Connector.open( "file:// "
+   curPath);
Enumeration   e   =   fc.list(musicName   +   ".* ",   true);
while   (e.hasMoreElements())   {
String   name   =   (String)   e.nextElement();
curPath   =   curPath   +   name;
if   (name.indexOf( "/ ")   >   -1)   {
getCurList(curPath,   musicName);
}   else   {
v2.addElement(new   LocalMusicBean(name,   curPath));
}
}
s   =   new   LocalMusicBean[v2.size()];
for   (int   i   =   0;   i   <   v2.size();   i++)   {
s[i]   =   (LocalMusicBean)   v2.elementAt(i);
}
v2.removeAllElements();
fc.close();
return   s;
}   catch   (IOException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
return   s;
}
}  

我下面该怎么写
突然想不明白了
请哪位大侠指正一下
谢谢

------解决方案--------------------
算法方面,递归有问题,
getCurList(curPath, musicName);
这里并没有把得到的内容加入到返回列表里,建议用集合类(比如Vector)来保存,而不是数组