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://chengdu.cdxwcx.cn/article/psiddo.html