Skip to content

Instantly share code, notes, and snippets.

@ahmeturganci
Created November 6, 2017 06:41
Show Gist options
  • Save ahmeturganci/f368107fabaaee1bc8b8e2c07370ba59 to your computer and use it in GitHub Desktop.
Save ahmeturganci/f368107fabaaee1bc8b8e2c07370ba59 to your computer and use it in GitHub Desktop.
Basic stream exapmle for c# -> (file oparation ex. fileread, filewrite, for c#) Raw
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace StreamApp
{
class Program
{
static void WriteFile(string Filename)
{
FileStream fileStream = new FileStream(Filename, FileMode.Create, FileAccess.Write);
if (fileStream.CanWrite)
{
byte[] buffer = Encoding.ASCII.GetBytes("MAHMUT TUNCER");
fileStream.Write(buffer, 0, buffer.Length);
}
fileStream.Flush();
fileStream.Close();
}
static void ReadFile(string Filename)
{
FileStream fileStream = new FileStream(Filename, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[1024];
int bytesread = fileStream.Read(buffer, 0, buffer.Length);
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesread));
fileStream.Close();
}
static void Main(string[] args)
{
string fileName = @"C:\ali\testt.txt";
WriteFile(fileName);
ReadFile(fileName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment