现在想要在jsp上呈现给用户一个指定机器的共享目录,请问可以有几种实现方法?
JCIFS除外

解决方案 »

  1.   

    代码参考。。  
    import   java.io.BufferedReader;  
      import   java.io.InputStreamReader;  
       
      /**  
      *   Determine   free   disk   space   for   a   given   directory   by    
      *   parsing   the   output   of   the   dir   command.  
      *   This   class   is   inspired   by   the   code   at  
      *   Works   only   under   Windows   under   certain   circumstances.  
      *   Yes,   it's   that   shaky.  
      *   Requires   Java   1.4   or   higher.  
      *   @[EMAIL   PROTECTED]    
      *Marco   Schmidt  
      */  
      public   class   Diskspace  
      {  
      private   Diskspace()  
      {  
      //   prevent   instantiation   of   this   class  
      }  
       
      /**  
      *   Return   available   free   disk   space   for   a   directory.  
      *   @[EMAIL   PROTECTED]  
      dirName   name   of   the   directory  
      *   @[EMAIL   PROTECTED]  
      free   disk   space   in   bytes   or   -1   if   unknown  
      */  
      public   static   long   getFreeDiskSpace(String   dirName)  
      {  
      try  
      {  
      //   guess   correct   'dir'   command   by   looking   at   the    
      //   operating   system   name  
      String   os   =   System.getProperty("os.name");  
      String   command;  
      if   (os.equals("Windows   NT")   ||  
      os.equals("Windows   2000"))  
      {  
      command   =   "cmd.exe   /c   dir   "   +   dirName;  
      }  
      else  
      {  
      command   =   "command.com   /c   dir   "   +   dirName;  
      }  
      //   run   the   dir   command   on   the   argument   directory   name  
      Runtime   runtime   =   Runtime.getRuntime();  
      Process   process   =   null;  
      process   =   runtime.exec(command);  
      if   (process   ==   null)  
      {  
      return   -1;  
      }  
      //   read   the   output   of   the   dir   command  
      //   only   the   last   line   is   of   interest    
      BufferedReader   in   =   new   BufferedReader(  
      new   InputStreamReader(process.getInputStream()));  
      String   line;  
      String   freeSpace   =   null;  
      while   ((line   =   in.readLine())   !=   null)  
      {  
      freeSpace   =   line;  
      }  
      if   (freeSpace   ==   null)  
      {  
      return   -1;  
      }  
      process.destroy();  
      //   remove   dots   &   commas   &   leading   and   trailing   whitespace  
      freeSpace   =   freeSpace.trim();  
      freeSpace   =   freeSpace.replaceAll("\\.",   "");  
      freeSpace   =   freeSpace.replaceAll(",",   "");  
      String[]   items   =   freeSpace.split("   ");  
      //   the   first   valid   numeric   value   in   items   after(!)   index   0  
      //   is   probably   the   free   disk   space  
      int   index   =   1;  
      while   (index   <   items.length)  
      {  
      try  
      {  
      long   bytes   =   Long.parseLong(items[index++]);  
      return   bytes;  
      }  
      catch   (NumberFormatException   nfe)  
      {  
      }  
      }  
      return   -1;  
      }  
      catch   (Exception   exception)  
      {  
      return   -1;  
      }    
      }  
       
      /**  
      *   Command   line   program   to   print   the   free   diskspace   to   stdout  
      *   for   all   26   potential   root   directories   A:\   to   Z:\  
      *   (when   no   parameters   are   given   to   this   program)  
      *   or   for   those   directories   (drives)   specified   as   parameters.  
      *   @[EMAIL   PROTECTED]  
      args   program   parameters  
      */  
      public   static   void   main(String[]   args)  
      {  
      if   (args.length   ==   0)  
      {  
      for   (char   c   =   'A';   c   <=   'Z';   c++)  
      {  
      String   dirName   =   c   +   ":\\";  
      System.out.println(dirName   +   "   "   +  
      getFreeDiskSpace(dirName));  
      }  
      }  
      else  
      {  
      for   (int   i   =   0;   i   <   args.length;   i++)  
      {  
      System.out.println(args[i]   +   "   "   +  
      getFreeDiskSpace(args[i]));  
      }  
      }  
      }  
      }   
      

  2.   

    谢谢,qiheia ,我研究一下.
      

  3.   

    其实采访windows共享目录直接使用java.io.File是可以采访的, 前提是当前运行帐号要有权限.