Advertisement
ivandrofly

Encoding (Read/Write)

Jul 29th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System.IO;
  2.  
  3. namespace EncodingTest
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Encoding encoding = Encoding.GetEncoding(860);
  10.             string content = "Não há de quê.";
  11.             File.WriteAllText("output.txt", content, encoding);
  12.  
  13.             // read the content correctly
  14.             string readContent = File.ReadAllText("output.txt", Encoding.UTF8);
  15.  
  16.             // faulty reading
  17.             string faultyReadContent = File.ReadAllText("output.txt", encoding);
  18.  
  19.             Console.WriteLine(readContent);
  20.             Console.WriteLine(faultyReadContent);
  21.  
  22.             Console.ReadLine();
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement