powered by simpleCommunicator - 2.0.56     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Ошибка в коде
3 сообщений из 3, страница 1 из 1
Ошибка в коде
    #39750189
nastyaa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Ребята почему у меня не работает код. Он должен открыть файл (xml или тхт) и в нем кириллицу конвертировать в латиницу. И с после конвертирования сохранить его в новый файл

Код: java
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('&#1241;', 'a');
        dictionary.put('б', 'b');
        dictionary.put('д', 'd');
        dictionary.put('е', 'e');
        dictionary.put('ф', 'f');
        dictionary.put('г', 'g');
        dictionary.put('&#1171;', '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('&#1187;', 'n');
        dictionary.put('о', 'o');
        dictionary.put('&#1257;', 'o');
        dictionary.put('п', 'p');
        dictionary.put('&#1179;', 'q');
        dictionary.put('р', 'r');
        dictionary.put('с', 's');
        dictionary.put('ш', 's');
        dictionary.put('ч', 'c');
        dictionary.put('т', 't');
        dictionary.put('&#1199;', 'u');
        dictionary.put('&#1201;', 'u');
        dictionary.put('в', 'v');
        dictionary.put('ы', 'y');
        dictionary.put('у', 'y');
        dictionary.put('з', 'z');
    }
 
    public Map<Character, Character> getDictionary() {
        return dictionary;
    }
}
...
Рейтинг: 0 / 0
Ошибка в коде
    #39750200
забыл ник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
nastyaaРебята почему у меня не работает код

Может зарплата не устраивает?
...
Рейтинг: 0 / 0
Ошибка в коде
    #39750319
Tsyklop
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
nastyaaРебята почему у меня не работает код.
Может потому что Вы так его написали?

Я вот не пойму людей которые ждут что за них сделают что-то. Какие же вы программисты тогда.
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Ошибка в коде
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]