-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDelete.java
More file actions
58 lines (47 loc) · 1.67 KB
/
FileDelete.java
File metadata and controls
58 lines (47 loc) · 1.67 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
package java2;
import java.io.*;
import java.util.ArrayList;
public class FileDelete extends FileHandler {
public static File outFile = new File("/Users/seonghun/공부/spring/network/src/java2/$$$$$$$$.txt");
public FileDelete() throws FileNotFoundException {
super();
fos = new FileOutputStream(outFile);
out = new PrintWriter(fos);
}
@Override
public void run() throws IOException {
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> e = new ArrayList<String>();
int equal = 0;
System.out.print("삭제 할 이름을 입력해주세요: ");
String name = scanner.nextLine();
String phone = "";
String thisLine = "";
while ((thisLine = in.readLine()) != null) {
list.add(thisLine);
if(thisLine.split(" ")[0].compareTo(name) == 0){
equal++;
e.add(thisLine);
}
}
if(equal == 0){
System.out.println("찾으시는 이름은 없습니다");
return;
}
if(equal >= 2){
e.forEach(System.out::println);
System.out.print("전화번호를 입력해주세요: ");
phone = scanner.nextLine();
}
for(int i = 0; i<list.size(); i++){
String s = list.get(i);
if(s.contains(e.get(0).split(" ")[0]) && s.contains(phone)){
continue;
}
out.println(list.get(i));
}
setStream();
phoneBook.delete();
outFile.renameTo(new File("/Users/seonghun/공부/spring/network/src/java2/phoneBook.txt"));
}
}