/**
* 递归查找文件
* @param basePath
* @param methodName
* @return
*/
private String Recurisive(String basePath, String methodName)
{
// TODO Auto-generated method stub
File file = new File(basePath);
File[] files = file.listFiles();
if(files==null)
{
return result;
}
String fileName = null;
for (int i = 0; i < files.length; i++) {
fileName = files[i].getName();
if(files[i].isDirectory()==true)
{
Recurisive(basePath+fileName+"/",methodName);
}else{
result = searchMethod(basePath,methodName,fileName);
if(!result.equals(UN_USER))
{
/*当搜索到关键字,则通过异常一次性跳出递归*/
throw new StopRecException();
}
}
}
return result;
}
static class StopRecException extends RuntimeException
{
/**
*
*/
private static final long serialVersionUID = 1L;
}
RuntimeException一次性中断退出递归函数
最新推荐文章于 2023-02-21 17:53:37 发布