最近想写一个可以删掉移动硬盘的java程序 注意,慎用,删除就没有了,禁止违法犯法 下面效果放上
代码
package cn.com.file; import java.io.File; import java.io.FileNotFoundException; public class DeletHd { private File f; public DeletHd() { f = new File("H:"); System.out.println(f.getPath()); try { Recurison(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void Recurison(File f) throws FileNotFoundException { // TODO Auto-generated method stub try { File[] dirname = null; dirname = f.listFiles(); for(File s : dirname) { if(s.isDirectory()) { Recurison(s); System.out.println(s.getName() + s.separator + s.delete()); }else { System.out.println(s.getName() + s.separator + s.delete()); } } } catch (Exception e) { // TODO: handle exception } } public static void main(String[] args) { // TODO Auto-generated method stub new DeletHd(); } }注意,慎用,删除就没有了,禁止利用违法