-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfolderAndFile
More file actions
39 lines (34 loc) · 901 Bytes
/
folderAndFile
File metadata and controls
39 lines (34 loc) · 901 Bytes
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
// this file contains some methods for creating and deleting a folder and a file
//1. create a folder
public void createDir(String path)...{
File dir=new File(path);
if(!dir.exists())
dir.mkdir();
}
//2. create a new file
public void createFile(String path,String filename) throws IOException...{
File file=new File(path+"/"+filename);
if(!file.exists())
file.createNewFile();
}
//3. delete a file
public void delFile(String path,String filename)...{
File file=new File(path+"/"+filename);
if(file.exists()&&file.isFile())
file.delete();
}
//4. delete a folder
public void delDir(String path)...{
File dir=new File(path);
if(dir.exists())...{
File[] tmp=dir.listFiles();
for(int i=0;i<tmp.length;i++)...{
if(tmp[i].isDirectory())...{
delDir(path+"/"+tmp[i].getName());
}
else...{tmp[i].delete();
}
}
dir.delete();
}
}