forked from tushartushar/DesigniteJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReader.java
More file actions
53 lines (43 loc) · 1.21 KB
/
FileReader.java
File metadata and controls
53 lines (43 loc) · 1.21 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 Designite.utils;
import java.io.File;
import java.util.ArrayList;
public class FileReader {
private ArrayList<String> pathList = new ArrayList<String>();
public FileReader(String sourcePath) {
listFiles(sourcePath);
}
public ArrayList<String> getPathList() {
return pathList;
}
// keeping all java files from the given path in a list
public void listFiles(String sourcePath) {
File f = null;
try {
f = new File(sourcePath);
if (f.isFile() && f.getAbsolutePath().endsWith(".java")) {
pathList.add(f.getAbsolutePath());
} else if (f.isDirectory()) {
getFilesFromFolder(f.getAbsolutePath());
} else {
// help menu
System.out.println("No file found to be analyzed.");
System.out.println("Usage instructions: ");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// adding java files of a folder in the List
public void getFilesFromFolder(String folderPath) {
File f = new File(folderPath);
File[] paths;
paths = f.listFiles();
for (File path : paths) {
if (path.isFile() && path.getAbsolutePath().endsWith(".java")) {
pathList.add(path.getAbsolutePath());
} else if (path.isDirectory()) {
getFilesFromFolder(path.getAbsolutePath());
}
}
}
}