I write the data from the buffer to a text file (Russian text). I tried it first

public static void WriteFinalInfoInFile() { string finalInfo = postTrack + " " + location + "\n"; File.AppendAllText("finalResult.txt", finalInfo); //write in file } 

then so

 public static void WriteFinalInfoInFile() { string finalInfo = postTrack + " " + location + "\n"; File.AppendAllText("finalResult.txt", finalInfo, Encoding.GetEncoding(1251)); //write in file } 

In both cases, Russian words are written as ????????????? ??????? ????????????? ??????? . There are no problems with the Latin record.

  • Try to open the notepad file through notepad ++ and check what encoding the data is displayed there. Perhaps should be set UTF-8. Also try to insert Russian characters instead of postTrack something like "string". Perhaps postTrack has a different encoding - user2455111
  • one
    @ user2455111 changed the string to string finalInfo = postTrack + "" + "hello" + "\ n"; all recorded correctly - cruim
  • then you need to transfer the location to the desired encoding, try to do it where you get the location. Perhaps there are Russian characters on the way and the encoding when read is set to another. And how do you get the location? - user2455111
  • @ user2455111 I tried to do this initially (do not set the encoding in the input parameters). in notepad ++ put utf + 8. all the same krakozyabry. can matters that wasps on the server English? I receive location from the buffer. - cruim
  • one
    From the name of the method: AppendAllText it is clear that it adds text to an already existing file. Accordingly, you need to add with the same encoding with which this file was created. I note that the default encoding is used, corresponding to the locale of the OS. Conclusion: always specify the encoding when writing / reading to / from the file (s). If you hesitate what to choose - take UTF-8. - Alexander Petrov

0