Đọc ghi file dữ liệu kiểu văn bản C#

Đọc ghi file kiểu dữ liệu là text (văn bản)

public class TextFileRead
{

public static void Run()
{

string fileName = Path.GetFullPath(“..\\..\\”) + “\\BinaryData.cs”; //input file
string outFile = Path.GetFullPath(“..\\..\\”) + “\\BinaryData2.bak”; //output file

FileStream inputStream = new FileStream(fileName,FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(inputStream);

FileStream outputStream = new FileStream(outFile,FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter writer = new StreamWriter(outputStream);
int text;
do
{

text = reader.Read();
Console.Write((char)text);
writer.Write(text);

}while (text!=-1);

reader.Close();
writer.Close();

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s