forked from vagabond1-1983/JavaRock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDemo.java
More file actions
28 lines (25 loc) · 763 Bytes
/
FileDemo.java
File metadata and controls
28 lines (25 loc) · 763 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
package com.test.basic.chapter7;
import java.io.File;
import java.io.IOException;
/**
* Created by beigui on 2016/2/18.
* 功能:File类的基本应用
*/
public class FileDemo {
public static void main(String[] args) {
File file = new File("D:/", "test.txt");
if (file.exists()) {
file.delete();
System.out.println("文件已删除");
} else {
try {
file.createNewFile();
System.out.println("文件已创建");
System.out.println("文件长度:" + file.length());
System.out.println("文件名:" + file.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}