我写了个方法用来遍历SD卡目录下的所有文件夹来搜索一个文件,不知道哪里出错了 求指教!
- Java code
private String searchImage(String key) { // TODO Auto-generated method stub String result=""; File[] files=new File("/sdcard/").listFiles(); for(File f : files){ if (f.isDirectory()) { searchImage(f.getPath()); // 系统提示这行报错 但是不知道怎么错的 } else { if (f.getName().equals(key)) { result=f.getPath(); } } } if (result.equals("")) { result="找不到啊"; } return result; }
------解决方案--------------------
可以参考
http://hilary3113.iteye.com/blog/1104798