-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
75 lines (60 loc) · 2.75 KB
/
Copy pathMain.java
File metadata and controls
75 lines (60 loc) · 2.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.Scanner;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws IOException{
System.out.println("Введите имя файла, который хотите найти.");
Scanner enter = new Scanner(System.in);
String nameFile = enter.nextLine();
while(!(Pattern.matches("^[^\\/?%*:|.;,]+.[^\\/?%*:|.,]{1,4}$", nameFile))){
System.out.println("Введите корректное имя файла с расширением.");
if(enter.hasNextLine()) {
nameFile = enter.nextLine();
}
}
Path name = Paths.get(nameFile);
Path file = Paths.get(name.toAbsolutePath().getRoot().toString());
MyFileVisitor h = new MyFileVisitor(name);
System.out.println("Подождите, выполняется поиск заданного файла...");
Files.walkFileTree(file, h);
if(h.isFind){
workWithFile a = new workWithFile(h.nameFile);
System.out.println("Файл был успешно найден!");
System.out.println("Расположение файла: " + a.name);
a.openFile();
System.out.println("Введите имя файла, в который будут записаны данные.");
nameFile = enter.nextLine();
while(!(Pattern.matches("^[^\\/?%*:|.;,]+.[^\\/?%*:|.,]{1,4}$", nameFile))){
System.out.println("Введите корректное имя файла с расширением.");
if(enter.hasNextLine()) {
nameFile = enter.nextLine();
}
}
name = Paths.get(nameFile);
file = Paths.get(name.toAbsolutePath().getRoot().toString());
h.nameFile = name;
h.isFind = false;
System.out.println("Подождите, выполняется поиск заданного файла...");
Files.walkFileTree(file, h);
if(h.isFind){
a.name = h.nameFile;
a.writeToFile();
}
else{
Path y = name.toAbsolutePath();
File w = new File(y.toUri());
if(w.createNewFile()){
System.out.println("Файл создан и расположен по пути " + w);
}
a.name = w.toPath();
a.writeToFile();
}
a.counter.clear();
}
else{
System.out.println("Не удалось найти файл с данным именем!");
}
}
}