generated from ohjelmointi2/gradle-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDictionaryReader.java
More file actions
38 lines (32 loc) · 1.08 KB
/
DictionaryReader.java
File metadata and controls
38 lines (32 loc) · 1.08 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
package wordplay.io;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
/**
* This class reads text files and returns a list of words from the file.
* The file is assumed to be in UTF-8 encoding and to only contain words,
* one word per line.
*/
public class DictionaryReader implements WordplayReader {
/**
* An utility method to read all Finnish words from the file.
*
* @return a list of all Finnish words
*/
public static List<String> readFinnishWords() {
WordplayReader reader = new DictionaryReader();
return reader.readFile(Path.of("data", "kaikkisanat.txt"));
}
@Override
public List<String> readFile(Path file) {
try {
// As the file contains just the words and nothing else,
// we do not need to skip any lines or do any other processing.
return Files.readAllLines(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}