using System;
using System.IO;namespace ConsoleApplication2
{
/// <summary>
/// Summary description for Class2.
/// </summary>
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();
}
}
}对文本文件进行读操作
原创
©著作权归作者所有:来自51CTO博客作者biyusr216的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:如何读INI文件中的设置信息
下一篇:读写文本的方法
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
文件操作-文本文件
c++读取和写入文本文件
写文件 文本文件 读文件 -
文件操作--文本文件读入
1696 Solv...
Math #define Web -
CCF编程能力等级认证GESP—C++7级—20250927
CCF编程能力等级认证GESP—C++7级—20250927
#c++ #算法 #数据结构 结点 时间复杂度
















