-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExample.java
More file actions
43 lines (40 loc) ยท 1.38 KB
/
FileExample.java
File metadata and controls
43 lines (40 loc) ยท 1.38 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
package ch18.sec11;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileExample {
public static void main(String[] args) throws IOException {
// File ๊ฐ์ฒด ์์ฑ
File dir = new File("temp/images");
File file1 = new File("temp/file1");
File file2 = new File("temp/file2");
File file3 = new File("temp/file3");
// ์กด์ฌํ์ง ์์ผ๋ฉด ๋๋ ํ ๋ฆฌ ๋๋ ํ์ผ ์์ฑ
if (!dir.exists()) {
dir.mkdirs();
}
if (!file1.exists()) {
file1.createNewFile();
}
if (!file2.exists()) {
file2.createNewFile();
}
if (!file3.exists()) {
file3.createNewFile();
}
// temp ํด๋์ ๋ด์ฉ์ ์ถ๋ ฅ
File temp = new File("temp");
File[] contents = temp.listFiles();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd a HH:mm");
for (File file : contents) {
System.out.printf("%-25s", simpleDateFormat.format(new Date(file.lastModified())));
if (file.isDirectory()) {
System.out.printf("%-10s%-20s", "<DIR>", file.getName());
} else {
System.out.printf("%-10s%-20s", file.length(), file.getName());
}
System.out.println();
}
}
}