forked from JavaWebinar/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.java
More file actions
53 lines (46 loc) · 1.49 KB
/
MainFile.java
File metadata and controls
53 lines (46 loc) · 1.49 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
package ru.javawebinar.basejava;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
/**
* gkislin
* 21.07.2016
*/
public class MainFile {
public static void main(String[] args) {
String filePath = ".\\.gitignore";
File file = new File(filePath);
try {
System.out.println(file.getCanonicalPath());
} catch (IOException e) {
throw new RuntimeException("Error", e);
}
File dir = new File("./src/ru/javawebinar/basejava");
System.out.println(dir.isDirectory());
String[] list = dir.list();
if (list != null) {
for (String name : list) {
System.out.println(name);
}
}
try (FileInputStream fis = new FileInputStream(filePath)) {
System.out.println(fis.read());
} catch (IOException e) {
throw new RuntimeException(e);
}
printDirectoryDeeply(dir, "");
}
public static void printDirectoryDeeply(File dir, String offset) {
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
System.out.println(offset + "F: " + file.getName());
} else if (file.isDirectory()) {
System.out.println(offset + "D: " + file.getName());
printDirectoryDeeply(file, offset + " ");
}
}
}
}
}