-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesUtil.java
More file actions
46 lines (42 loc) · 1.39 KB
/
FilesUtil.java
File metadata and controls
46 lines (42 loc) · 1.39 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
package AnalyzerPackage;
import java.io.*;
import java.util.ArrayList;
//This class reads all the selected files by the user.
public class FilesUtil {
public String readFiles(ArrayList<String> filePaths) {
String fileAsString = "";
try {
for (int i = 0; i < filePaths.size(); i++) {
BufferedReader reader = new BufferedReader(new FileReader(filePaths.get(i)));
while (true) {
String s = reader.readLine();
if (s == null) {
break;
}
fileAsString += (s + "\n");
}
reader.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fileAsString;
}
public ArrayList<String> readFolder(String path) {
File file = new File(path);
String[] files = file.list();
if (files == null) {
System.out.println("there is no files or directories in current path");
return null;
}
ArrayList<String> filesList = new ArrayList<>();
for (String s : files) {
if (s.indexOf(".java") > 0 || s.indexOf(".txt") > 0) {
filesList.add(path + "\\" + s);
}
}
return filesList;
}
}