718186593eb86156c43e0ff934106964b4a2b967.svn-base
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.espeed.yxy.tool;
import java.io.File;
/***
*
* @author xieyong
* 生成删除文件
*/
public class GreateAndDeleteFile {
/**用于创建文件夹的方法*/
public static void mkdir(String mkdirName)throws Exception{
File dirFile = new File(mkdirName);
boolean bFile = dirFile.exists();
if( bFile == true )
{
System.out.println("The folder exists.");
} else {
System.out.println("The folder do not exist,now trying to create a one...");
bFile = dirFile.mkdirs();
if( bFile == true )
{
System.out.println("Create successfully!");
System.out.println("创建文件夹");
}
else{
System.out.println("Disable to make the folder,please check the disk is full or not.");
System.out.println(" 文件夹创建失败,清确认磁盘没有写保护并且空件足够");
}
}
}
/**删除文件夹*/
public static void deleteFile(File file){
try {
if(file.exists()){
if(file.isFile()){
file.delete();
}else if(file.isDirectory()){
File files[] = file.listFiles();
for(int i=0;i<files.length;i++){
deleteFile(files[i]);
}
}
file.delete();
}else{
System.out.println("所删除的文件不存在!"+'\n');
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**用于创建文件的方法*/
public static void createFile(String mkdirName) throws Exception{
File dirFile = new File(mkdirName);
boolean bFile = dirFile.exists();
if( bFile == true )
{
System.out.println("The folder exists.");
} else {
System.out.println("The folder do not exist,now trying to create a one...");
bFile = dirFile.createNewFile();
if( bFile == true )
{
System.out.println("Create successfully!");
System.out.println("创建文件夹");
}
else{
System.out.println("Disable to make the folder,please check the disk is full or not.");
System.out.println(" 文件夹创建失败,清确认磁盘没有写保护并且空件足够");
}
}
}
public static void main(String[] agrs){
GreateAndDeleteFile caf = new GreateAndDeleteFile();
File file = new File("E:\\javawork\\.metadata\\.me_tcat\\webapps\\espeedYxyService\\mailtempfile\\21xmail.com\\xieyong\\attachment\\0d161f8a-7091-492c-bf1b-a394470a63a8.xls");
caf.deleteFile(file);
}
}