Repository navigation
Expand file tree
/
Copy pathWordStatInput.java
More file actions
56 lines (49 loc) · 2.13 KB
/
Copy pathWordStatInput.java
File metadata and controls
56 lines (49 loc) · 2.13 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
import java.io.*;
import java.util.*;
public class WordStatInput {
public static void main(String[] args) {
try {
HashMap<String, Integer> output = new HashMap<>();
String fileNameInput = args[0];
String fileNameOutput = args[1];
BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(fileNameInput), "UTF-8"));
BufferedWriter outputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileNameOutput), "UTf-8"));
String keys = "";
while (input.ready()) {
String line = input.readLine().toLowerCase() + " ";
int i = 0;
String word = "";
while (i < line.length()) {
if ((line.charAt(i) == '\'') || (Character.DASH_PUNCTUATION == Character.getType(line.charAt(i))) || (Character.isLetter(line.charAt(i)))) {
word += line.charAt(i);
} else {
if (word.length() != 0) {
if ((output.containsKey(word))) {
output.put(word, output.get(word) + 1);
} else {
output.put(word, 1);
keys = keys + word + " ";
}
}
word = "";
}
i++;
}
}
keys.strip();
String[] SpisokKeys = keys.split(" ");
for (int j = 0; j < SpisokKeys.length; j++) {
outputFile.write(SpisokKeys[j] + " " + Integer.toString(output.get(SpisokKeys[j])) + "\n");
}
input.close();
outputFile.close();
} catch (FileNotFoundException e) {
System.err.println("Error FNFE");
} catch (UnsupportedEncodingException e) {
System.err.println("Error UEE");
} catch (IOException e) {
System.err.println("Error IOE");
}
}
}
//Вывод ошибок и названия переменных