我的目的是访问特定的文件夹,读取里面所有的图片文件名
假定图片目录是 //image/

解决方案 »

  1.   

    import   java.io.*;   
      public   class   Decode   
      {   
              static   String   is_jadpath;   
      public   static   void   main(String[]   args)     
      {   
              try{   
                      if   (args.length>1)   
                      {   
                              is_jadpath=args[0];   
                              File   f=new   File(args[1]);   
                              if   (f.isDirectory())   
                              {   
                                              File   newdic=new   File(args[1]+"_src");   
                                              newdic.mkdir();   
                                              recursionFileList(newdic.getPath(),f);   
                              }   
                              else   
                              {   
                                              Runtime   r=Runtime.getRuntime();   
                                              String   dimpath=args[1].substring(0,args[1].lastIndexOf('\\'));   
                                              String   cmd=is_jadpath+"   -d   "+dimpath+"   -s   java   "+args[1];   
                                              r.exec(cmd);   
                              }   
                      }   
                      else   
                      {   
                              System.out.println("please   input   argument");   
                              System.out.println("example   d:\\jadhome\\jad   c:\\yourdic\\yourclass.class");   
                      }   
              }catch(Exception   e)   
              {System.out.println("wrong:"+e);}   
                
              }   
              private   static   boolean   recursionFileList(String   dimparentpath,File   f)   
              throws   Exception   
              {   
                      boolean   hasClassFile=false;   
                      File   flist[]=f.listFiles();   
              for(int   i=0;i<flist.length;i++)   
              {   
                              if   (flist[i].isDirectory())     
                              {   
                                      String   srcpath=flist[i].getPath();   
                                      String   dimpath=dimparentpath+srcpath.substring(srcpath.lastIndexOf('\\'));   
                                      File   newdic=new   File(dimpath);   
                                      newdic.mkdir();   
                                      if   (!recursionFileList(dimpath,flist[i]))     
                                              newdic.delete();   
                                      else   
                                      {   
                                              Runtime   r=Runtime.getRuntime();   
                                              String   cmd=is_jadpath+"   -d   "+dimpath+"   -s   java   "+srcpath+"\\*.class";   
                                              r.exec(cmd);   
                                      }   
                              }   
                              else   if   (flist[i].getPath().endsWith(".class"))   
                              {   
                                      hasClassFile=true;   
                                      Runtime   r=Runtime.getRuntime();   
                                      String   cmd=is_jadpath+"   -d   "+dimparentpath+"   -s   java   "+flist[i].getPath();   
                                      r.exec(cmd);   
                              }   
                      }   
                      return   hasClassFile;   
              }   
      }   上面是java遍历一个目录,并读出其中所有的文件名,楼主参考一下
      

  2.   

    利用ServletContext获得图片文件夹真实路径,参照楼上方法可读出文件名。
      

  3.   

    用FILE读一个目录下文件的集合 应该不是太难吧 不过如果你是通过客户端访问服务端并且想访问服务端的目录的集合那不太可能 除非服务端给你提供这个功能我这里有个JSP文件 是一般小公司用来管理服务器文件的东西(偶尔也会被黑客拿去用) 如果你想要的话留下邮箱 我发给你
      

  4.   

    我来推荐一个在线试听课程http://www.cdlanah.com/zxst/