如何对文本文件进行操作?

googlequ 2004-11-06 11:03:16
如何对文本文件进行操作?
...全文
107 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
czhenq 2004-11-06
  • 打赏
  • 举报
回复
查看System.IO命名空间
zhounet 2004-11-06
  • 打赏
  • 举报
回复
public class Class1
{
private const string FILE_NAME="MyFile.txt";
public static void Main(String[] args)
{
if(!File.Exists(FILE_NAME)) //如果不文件存在,则抛出异常
{
Console.WriteLine("{0} does not exist!",FILE_NAME);
}

StreamReader sr=File.OpenText(FILE_NAME);
String input;
while((input=sr.ReadLine())!=null)
{
Console.WriteLine(input);
}
Console.WriteLine("The end of the Stream has been reched.");
sr.Close();
}
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧