⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filehandle.java

📁 分布式计算平台P2HP-1的源代码;P2HP-1是基于P2P的高性能计算平台
💻 JAVA
字号:
/*
 * Created on 2005-9-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.edu.hust.cgcl.biogrid.worker;

import java.io.File;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class FileHandle {
	
	/**
	 * del a file folder which is enmpty.
	 * @param path
	 */
	public static void delFolder(String path)
	{
		try {
		      delAllFile(path); //删除完里面所有内容
		      String filePath = path;
		      File myFilePath = new File(filePath);
		      myFilePath.delete(); //删除空文件夹
		      //System.out.println("delfolder: "+filePath);

		    }
		    catch (Exception e) {
		      System.out.println("删除文件夹操作出错");
		      e.printStackTrace();

		    }
	
	}
	
	/**
	 * del a file with all of his subfolders and files.
	 * @param path
	 */
	public static void delAllFile(String path)
	{
		File f=new File(path);
		if(!f.exists())
			return;
		if(!f.isDirectory())
			f.delete();
		String[] tempList=f.list();
		File temp=null;
		for(int i=0;i<tempList.length;i++)
		{
		      if (path.endsWith(File.separator)) {
		        temp = new File(path + tempList[i]);
		      }
		      else {
		        temp = new File(path + File.separator + tempList[i]);
		      }
		      if (temp.isFile()) {
		        temp.delete();
		        //System.out.println("del: "+path + File.separator + tempList[i]);
		      }
		      if (temp.isDirectory()) {
		        delAllFile(path + File.separator + tempList[i]);//先删除文件夹里面的文件
		        delFolder(path + File.separator + tempList[i]);//再删除空文件夹
		      }
		    }
		return;		  
	}	
	
	public static void delAllFolder(String path)
	{
		delAllFile(path);
		delFolder(path);
	}
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -