P
P
Pavel Bykov2018-02-04 21:35:13
Android
Pavel Bykov, 2018-02-04 21:35:13

How to fix Cyrillic encoding in android?

Hello, I can’t understand why this code for reading a previously created file in the internal android system displays something incomprehensible in places of the Russian language =>

try {
    FileInputStream fileInputStream = context.openFileInput(fileIniInfo);
    int ch;
    StringBuffer result = new StringBuffer();
    while((ch = file.read()) != -1) {
        result.append((char)ch);
    }
    return result.toString();
} catch (IOException e) {
     e.printStackTrace();
}

Here is the text that is displayed both in the TextView in android and in log.d
{"fullName":"ÃÂÃÂøòõàüøÃÂ", "id":"0", "countEnter":1}

Here is the code that writes the file =>
try {
    FileOutputStream fileOutputStream = context.openFileOutput(fileIniInfo, Context.MODE_PRIVATE);
    BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "utf8"));
    String result = object.toString();
    wr.write(result);
    wr.close();
} catch (IOException e) {
    e.printStackTrace();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Bykov, 2018-02-04
@mafof

Solved the problem by rewriting the file open method, now it looks like this =>

BufferedReader br = new BufferedReader(new InputStreamReader(file));
return br.readLine(); // В данном случае мой файл будет всегда в одну строку!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question