免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2201 | 回复: 4
打印 上一主题 下一主题

为什么只打印了第一个目录里的文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-29 20:56 |只看该作者 |倒序浏览
我的api下的所有文件被挂马了,我便想写段代码找到那些网页被挂马了代码如下:
public void findHtml(){
  String path= "E:\\database-E\\Java\\"
     + "API\\html_zh_CN\\";
  File file = new File(path);
  String [] str= file.list();
  int len = str.length;
  for(int i=0;i<str.length;i++){
   File tmp = new File(path,str);
   if(tmp.isDirectory()){
    System.out.println(tmp.getName()+" is Directory");
    String [] tmpStr= tmp.list(new FilenameFilter(){ public boolean
              accept(File dir,String name)
       { return name.indexOf(".html")!=-1; } });
    for(int n=0;n<tmpStr.length;n++){
     System.out.println(tmpStr[n].toString());
    }
   }
  }
}
怎么只能打印出第一个目录下的所有html文件其他目录下的html文件都不能打印啊?

论坛徽章:
0
2 [报告]
发表于 2009-08-30 01:10 |只看该作者
   File tmp = new File(path,str);

这一句里path没变化,所以只有该目录下的文件!
比较一下:

  1.     public void search(String path, String ext)
  2.     {
  3.         File curFile = new File(path);
  4.         File[] allFiles = curFile.listFiles();
  5.         for(File f : allFiles)  {
  6.             if(f.isDirectory()) search(f.getAbsolutePath(), ext);
  7.             else {
  8.                 if(f.getName().indexOf("." + ext) > 0)
  9.                     System.out.println(f.getAbsolutePath());
  10.             }
  11.         }
  12.     }
复制代码

[ 本帖最后由 caojiqun 于 2009-8-30 01:40 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2009-08-30 02:01 |只看该作者
而来说的很对,我已经看到了。正在重写中,谢谢啊.还有什么好的意见吗

论坛徽章:
0
4 [报告]
发表于 2009-08-31 22:00 |只看该作者
代码写规范点,有点乱

论坛徽章:
0
5 [报告]
发表于 2009-09-05 18:10 |只看该作者
好方法啊 递归
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP