Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8.  
  9. namespace Reader
  10. {
  11.     class Program
  12.     {
  13.        // public static System.Text.Encoding OutputEncoding = UTF8Encoding.Default;
  14.         static void Main(string[] args)
  15.         {
  16.  
  17.             // \native\language\ru.json для дебага и
  18.             // \resources\language\ru.json для билда
  19.             var rootPath = AppDomain.CurrentDomain.BaseDirectory;
  20.             //if(Directory.Exists(Path.Combine(rootPath, "resources")))
  21.             //{
  22.              //   rootPath = Path.Combine(rootPath, "resources");
  23.            // }
  24.             //System.Windows.Forms.MessageBox.Show(rootPath);
  25.             var culture = System.Globalization.CultureInfo.CurrentCulture;
  26.            
  27.             try
  28.             {
  29.                 try
  30.                 {
  31.  
  32.                     //System.Windows.Forms.MessageBox.Show(Environment.CurrentDirectory);
  33.                     FileStream file1 = new FileStream(rootPath + "\\native\\language\\" + culture.ToString() + ".json", FileMode.Open); //создаем файловый поток
  34.                     StreamReader reader = new StreamReader(file1); // создаем «потоковый читатель» и связываем его с файловым потоком
  35.  
  36.                     var text = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd()));
  37.                     //  System.Convert.ToBase64String(reader.ReadToEnd()); - ОШИБКА
  38.                     Console.Write(text); //считываем все данные с потока и выводим на экран
  39.                    
  40.                     reader.Close(); //закрываем поток
  41.                    
  42.                 }
  43.                 catch (System.IO.DirectoryNotFoundException) {
  44.                     System.Windows.Forms.MessageBox.Show("Err" + rootPath + "\\native\\language\\ru.json");
  45.                 }
  46.                 //FileStream file1 = new FileStream(Environment.CurrentDirectory + "native\\language\\ru.json", FileMode.Open); //создаем файловый поток
  47.        
  48.                // Console.ReadLine();
  49.  
  50.             }
  51.             catch (System.IO.FileNotFoundException)
  52.             {
  53.                 System.Windows.Forms.MessageBox.Show("Language file does not found! " + rootPath + "\\test.txt");
  54.                // Console.ReadLine();
  55.             }
  56.        
  57.            
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement