-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleApp.java
More file actions
44 lines (42 loc) · 1.94 KB
/
ConsoleApp.java
File metadata and controls
44 lines (42 loc) · 1.94 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
import java.io.*;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
public class ConsoleApp {
public static void main(String[] args) throws IOException {
String line;
BufferedReader reader = new BufferedReader(new FileReader(args[0])); // чтение файла,который задается первым аргументом командной строки
ArrayList<String> list = new ArrayList<>();
while ((line = reader.readLine()) != null) {
list.add(line);
}
Killer killer = new Killer(); //создаем поток,который отменяет запущенные поиски нажатием клавиши esc
killer.start();
FileWriter fw = new FileWriter(args[1]); // создаем файл
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw);
out.print("");
for (int i = 0; i < list.size(); i++) {
File Directory = new File(list.get(i));
FolderSearch counter = new FolderSearch(Directory);
FutureTask <Integer> task = new FutureTask<>(counter);
Thread t = new Thread(task);
t.start();
try {
int k = i + 1;
System.out.println(k + "\t" + task.get() + "\t" + Directory); //выводим на экран
out.println( list.get(i)+ ";" + task.get()); //записываем в файл
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
}
out.close();
if (killer.isAlive()) {
System.out.println("Press any key to continue...");
}
}
public static void interruptT() { // метод меняющий значение флаговой переменной
FolderSearch.flag = false;
}
}