-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileTest.java
More file actions
60 lines (44 loc) · 1.05 KB
/
FileTest.java
File metadata and controls
60 lines (44 loc) · 1.05 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
/*
* 功能:File类基本用法
* 1、创建
* 2、使用
*/
package com.bj.io;
import java.io.*;
public class FileTest {
public static void main(String[] args) {
// //创建文件对象
// File file=new File("D:/aa.txt");
// //得到文件路径
// System.out.println("文件路径:"+file.getAbsolutePath());
// //得到文件名
// System.out.println("文件名:"+file.getName());
//
// if(file.exists()==false){
// System.out.println("File Not Exist");
// }
// //创建文件和文件夹
// File file=new File("D:/www/nb.txt");
// if(file.exists()==false){
// try {
// file.createNewFile();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }else{
// System.out.println("文件存在,不创建");
// }
//创建文件夹
File files=new File("D:/www");
if(files.isDirectory()){
System.out.println("文件目录存在");
File list[]=files.listFiles();
for(int i=0;i<list.length;i++){
System.out.println("文件名:"+list[i].getName());
}
}else{
files.mkdir();
}
}
}