📄 filehandle.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 + -