-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
58 lines (56 loc) · 1.52 KB
/
Copy pathReadFile.java
File metadata and controls
58 lines (56 loc) · 1.52 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.*;
import java.util.*;
public class ReadFile {
private Scanner x;
public void openFile(){
try{
x = new Scanner(new File("words.txt"));
}
catch(Exception e){
System.out.println("oops, couldn't find my dictionary!");
}
}
public void readFile(){
while(x.hasNext()){
String a = x.next();
System.out.printf(a + "\n");
}
}
public void closeFile(){
x.close();
}
//create a hashset out of txt file
//this will be used to check user input
public Set<String> createSet(){
Set<String> words = new HashSet<>();
try{
x = new Scanner(new File("words.txt"));
}
catch(Exception e){
System.out.println("oops, couldn't find my dictionary!");
}
while(x.hasNext()){
String a = x.next();
words.add(a);
}
return words;
}
//create a List out of txt file
//this will be used to generate the initial word
public ArrayList<String> createList(){
ArrayList<String> nineLetterWords = new ArrayList<>();
try{
x = new Scanner(new File("words.txt"));
}
catch(Exception e){
System.out.println("oops, couldn't find my dictionary!");
}
while(x.hasNext()){
String a = x.next();
if(a.length() == 9){
nineLetterWords.add(a);
}
}
return nineLetterWords;
}
}