前沿拓展:
无法删除文件夹 目录不是空的
开始划均团这场指再-运行-cmd
举例您的这个目录在F:\test\test123
F:
cd test\test123
rd . /s/q
第二在退出之后删除test123文件夹。
import java.io.File;
public class DeleteFolder {
/***
* @param: String filePath 文件路径
* @desc: (1)删除文件夹中的文件
* */
public void delFolder(String filePath ) throws Exception {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
String fileItmTemp = fileItm.getAbsolutePath();
if(fileItm.isDirectory()) {
delFolder(fileItmTemp);
} else {
fileItm.delete();
}
}
}
/***
* @param: String filePath 文件路径
* @desc: (1)删除级联空文件夹
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 测试代码
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知识:
前沿拓展:
无法删除文件夹 目录不是空的
开始划均团这场指再-运行-cmd
举例您的这个目录在F:\test\test123
F:
cd test\test123
rd . /s/q
第二在退出之后删除test123文件夹。
import java.io.File;
public class DeleteFolder {
/***
* @param: String filePath 文件路径
* @desc: (1)删除文件夹中的文件
* */
public void delFolder(String filePath ) throws Exception {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
String fileItmTemp = fileItm.getAbsolutePath();
if(fileItm.isDirectory()) {
delFolder(fileItmTemp);
} else {
fileItm.delete();
}
}
}
/***
* @param: String filePath 文件路径
* @desc: (1)删除级联空文件夹
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 测试代码
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知识:
前沿拓展:
无法删除文件夹 目录不是空的
开始划均团这场指再-运行-cmd
举例您的这个目录在F:\test\test123
F:
cd test\test123
rd . /s/q
第二在退出之后删除test123文件夹。
import java.io.File;
public class DeleteFolder {
/***
* @param: String filePath 文件路径
* @desc: (1)删除文件夹中的文件
* */
public void delFolder(String filePath ) throws Exception {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
String fileItmTemp = fileItm.getAbsolutePath();
if(fileItm.isDirectory()) {
delFolder(fileItmTemp);
} else {
fileItm.delete();
}
}
}
/***
* @param: String filePath 文件路径
* @desc: (1)删除级联空文件夹
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 测试代码
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知识:
前沿拓展:
无法删除文件夹 目录不是空的
开始划均团这场指再-运行-cmd
举例您的这个目录在F:\test\test123
F:
cd test\test123
rd . /s/q
第二在退出之后删除test123文件夹。
import java.io.File;
public class DeleteFolder {
/***
* @param: String filePath 文件路径
* @desc: (1)删除文件夹中的文件
* */
public void delFolder(String filePath ) throws Exception {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
String fileItmTemp = fileItm.getAbsolutePath();
if(fileItm.isDirectory()) {
delFolder(fileItmTemp);
} else {
fileItm.delete();
}
}
}
/***
* @param: String filePath 文件路径
* @desc: (1)删除级联空文件夹
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 测试代码
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知识:
原创文章,作者:九贤生活小编,如若转载,请注明出处:http://www.wangguangwei.com/95380.html