using System;
using System.IO;
class predefinedTypes
{
public static void Main()
{
// 在当前目录创建一个文件myfile.txt,对该文件具有读写权限
FileStream fsMyfile = new FileStream("myfile.txt" , FileMode.Create , FileAccess.ReadWrite);
//写入
StreamWriter swMyfile = new StreamWriter(fsMyfile);
string wd=Console.ReadLine();
swMyfile.WriteLine(wd);
swMyfile.Flush();
//读出
StreamReader srMyfile= new StreamReader(fsMyfile);
srMyfile.BaseStream.Seek(0, SeekOrigin.Begin);
string rl=srMyfile.ReadLine();
Console.WriteLine(rl);
}
}
新闻名称:C#创建文本文件,写入数据,输出数据
转载源于:
http://bzwzjz.com/article/psiddo.html