-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThanos.java
More file actions
58 lines (53 loc) · 2.28 KB
/
Thanos.java
File metadata and controls
58 lines (53 loc) · 2.28 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
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Thanos {
public static void main(String[] args)throws Exception {
String fileName = "C:\\Users\\Chiefky\\Documents\\Programming\\Thanos\\thanosReal.txt";
String name = "Thanos"; // character name
try (Stream<String> stream = Files.lines(Paths.get(fileName))){
List<String> lines = stream.collect(Collectors.toList());
//List<String> quotes = new ArrayList<>();
PrintWriter writer = new PrintWriter("C:\\Users\\Chiefky\\Documents\\Programming\\Thanos\\thanosOut.txt", "UTF-16");
boolean reading = false;
boolean newLine = true;
String thisQuote = "";
String afterPunc = "";
for (int i = 0; i < lines.size(); i++){
for (String s : lines.get(i).split(" ")) {
if (reading == true){
if (s.endsWith(":") && newLine){
reading = false;
//quotes.add(thisQuote);
System.out.println(thisQuote);
writer.println(thisQuote);
thisQuote = "";
afterPunc = "";
}else if (s.endsWith("]") || s.endsWith(".") || s.endsWith("?") || s.endsWith("!")){
thisQuote += afterPunc + s + " ";
afterPunc = "";
}else if (!s.equals("")){
afterPunc += s + " ";
}
}else if (s.equals(name +":")){
thisQuote += s + " ";
reading = true;
newLine = false;
}
}
newLine = true;
}
//quotes.add(thisQuote);
writer.println(thisQuote);
System.out.println(thisQuote);
writer.close();
}catch (IOException e){
e.printStackTrace();
}
}
}