java删除文件

package change;

/**
* 运用DOS命令来执行文件的删除
* @author DanielCooger
*<a href="mailto:[email protected]">daniel</a>
*/
public class Deldoc {

 /**
  *
  * @param file
  *    要删除文件的绝对路径
  * @return boolean
  * @throws Exception
  */
 public boolean del(String file) throws Exception {
  if (file.equals("") || file == null) {
   throw new NullPointerException("信息不全,无法删除文件");
  } else {
   String delete="c:\\windows\\system32\\cmd.exe /C  del " + file;
   Runtime rt = Runtime.getRuntime();
   try {
    rt.exec(delete);
    return true;
   } catch (Exception e) {
    throw new Exception("删除文件失败");
   }
  }
 }

}

你可能感兴趣的:(java,c,windows,dos,Gmail)