Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace ConsoleApp6
- {
- class Program
- {
- private static void AddTexttoFile(FileStream file, string value)
- {
- byte[] info = new UTF8Encoding(true).GetBytes(value);
- file.Write(info, 0, info.Length);
- }
- static void Main(string[] args)
- {
- string fileName = @"E:\text.txt";
- using (FileStream file = File.Create(fileName))
- {
- AddTexttoFile(file, "Hi");
- AddTexttoFile(file, " Welcome \n");
- AddTexttoFile(file, "To Armenia");
- }
- if (File.Exists(fileName))
- {
- using (FileStream file = File.OpenRead(fileName))
- {
- byte[] b = new byte[100];
- UTF8Encoding encode = new UTF8Encoding(true);
- while (file.Read(b, 0, b.Length) > 0)
- {
- Console.WriteLine(encode.GetString(b));
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment