`

通过命令删除文件或文件夹

    博客分类:
  • JAVA
阅读更多
  1. /**  
  2.      * 通过命令删除文件或文件夹(会删除文件夹里所有文件) 只能在windows上使用,如果  
  3.      * 在Unix或linux上,则修改相应命令  
  4.      *   
  5.      * @param _file  
  6.      */  
  7.      public static void deleteFileByWindowsCommand(File _file) {   
  8.          Runtime rt = Runtime.getRuntime();      
  9.          String cmd = null;   
  10.           try {      
  11.               if(_file.isFile()) {   
  12.                   cmd = "cmd.exe /c del /q/a/f/s "+_file.getAbsolutePath();   
  13.               } else {   
  14.                   cmd = "cmd.exe /c rd /s/q "+_file.getAbsolutePath();   
  15.               }   
  16.               rt.exec(cmd);      
  17.           }catch(IOException e){      
  18.               e.printStackTrace();      
  19.           }      
  20.         }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics