-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.java
More file actions
53 lines (45 loc) · 1.48 KB
/
MainFile.java
File metadata and controls
53 lines (45 loc) · 1.48 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
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
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/com/dofler/webapp");
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);
}
getListFiles(dir, 0);
}
public static void getListFiles(File file, int offset) {
for (int i = 0; i < offset; i++) {
System.out.print(" ");
}
System.out.println(file.getName());
if (file.isDirectory()) {
offset++;
}
if (file.isDirectory()) {
String[] listOfFilesOrDirectories = file.list();
if (listOfFilesOrDirectories != null) {
for (String fileOrDirectory : listOfFilesOrDirectories) {
getListFiles(new File(file, fileOrDirectory), offset);
}
}
}
}
}