Ошибка в коде
#39750189
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Ребята почему у меня не работает код. Он должен открыть файл (xml или тхт) и в нем кириллицу конвертировать в латиницу. И с после конвертирования сохранить его в новый файл
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. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88.
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
String inputFilePath = "C:\\Users\\Nastya\\Desktop\\Первый перевод\\strings2a_kz.txt";
String outputFilePath = "C:\\Users\\Nastya\\Desktop\\Первый перевод\\output.txt";
FileReader fileReader = new FileReader(inputFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
FileWriter fileWriter = new FileWriter(outputFilePath);
String line;
StringBuilder result = new StringBuilder();
Map<Character, Character> dictionary = new Dictionary().getDictionary();
while ((line = bufferedReader.readLine()) != null) {
result.append(convertString(line, dictionary) + System.getProperty("line.separator")) ;
}
bufferedReader.close();
fileReader.close();
fileWriter.write(result.toString());
fileWriter.flush();
fileWriter.close();
}
public static String convertString(String str, Map<Character, Character> dictionary) {
char[] chars = str.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
if (dictionary.containsKey(chars[i])) {
stringBuilder.append(dictionary.get(chars[i]));
continue;
}
stringBuilder.append(chars[i]);
}
return stringBuilder.toString();
}
}
class Dictionary {
private Map<Character, Character> dictionary;
public Dictionary() {
dictionary = new HashMap<>();
dictionary.put('а', 'a');
dictionary.put('ә', 'a');
dictionary.put('б', 'b');
dictionary.put('д', 'd');
dictionary.put('е', 'e');
dictionary.put('ф', 'f');
dictionary.put('г', 'g');
dictionary.put('ғ', 'g');
dictionary.put('х', 'h');
dictionary.put('h', 'h');
dictionary.put('і', 'i');
dictionary.put('и', 'i');
dictionary.put('й', 'i');
dictionary.put('ж', 'j');
dictionary.put('к', 'k');
dictionary.put('л', 'l');
dictionary.put('м', 'm');
dictionary.put('н', 'n');
dictionary.put('ң', 'n');
dictionary.put('о', 'o');
dictionary.put('ө', 'o');
dictionary.put('п', 'p');
dictionary.put('қ', 'q');
dictionary.put('р', 'r');
dictionary.put('с', 's');
dictionary.put('ш', 's');
dictionary.put('ч', 'c');
dictionary.put('т', 't');
dictionary.put('ү', 'u');
dictionary.put('ұ', 'u');
dictionary.put('в', 'v');
dictionary.put('ы', 'y');
dictionary.put('у', 'y');
dictionary.put('з', 'z');
}
public Map<Character, Character> getDictionary() {
return dictionary;
}
}
|
|