前沿拓展:
無法刪除文件夾 目錄不是空的
開始劃均團(tuán)這場(chǎng)指再-運(yùn)行-cmd
舉例您的這個(gè)目錄在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)刪除級(jí)聯(lián)空文件夾
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 測(cè)試代碼
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知識(shí):
前沿拓展:
無法刪除文件夾 目錄不是空的
開始劃均團(tuán)這場(chǎng)指再-運(yùn)行-cmd
舉例您的這個(gè)目錄在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)刪除級(jí)聯(lián)空文件夾
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 測(cè)試代碼
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知識(shí):
前沿拓展:
無法刪除文件夾 目錄不是空的
開始劃均團(tuán)這場(chǎng)指再-運(yùn)行-cmd
舉例您的這個(gè)目錄在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)刪除級(jí)聯(lián)空文件夾
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 測(cè)試代碼
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知識(shí):
前沿拓展:
無法刪除文件夾 目錄不是空的
開始劃均團(tuán)這場(chǎng)指再-運(yùn)行-cmd
舉例您的這個(gè)目錄在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)刪除級(jí)聯(lián)空文件夾
* */
public void deleteRealFolder(String filePath) {
File file = new File(filePath);
File[] fileList = file.listFiles();
for(File fileItm : fileList) {
deleteRealFolder(fileItm.getAbsolutePath());
fileItm.delete();
}
}
}
// 測(cè)試代碼
String filePath = "C:\\logs";
DeleteFolder deleteFolder = new DeleteFolder();
deleteFolder.delFolder(filePath);
deleteFolder.deleteRealFolder(filePath);
拓展知識(shí):
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請(qǐng)注明出處:http:///95380.html