手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#控制台进行文件读写的方法
C#控制台进行文件读写的方法
摘要:本文实例讲述了C#控制台进行文件读写的方法。分享给大家供大家参考。具体如下:C#控制台进行文件写入:usingSystem;usingSys...

本文实例讲述了C#控制台进行文件读写的方法。分享给大家供大家参考。具体如下:

C#控制台进行文件写入:

using System; using System.IO; class file1 { public static void Main() { string PATH = null; Console.WriteLine("file path: "); //这里输入文本所在目录 例如 d:text.txt PATH = Console.ReadLine(); StreamWriter sw = new StreamWriter(PATH); string str = null; while(true){ str = Console.ReadLine(); if (str == "end") { break; } sw.WriteLine(str); } sw.Close(); Console.ReadKey(); } }

C#控制台进行文件读取

using System; using System.IO; class file1 { public static void Main() { string PATH = null; Console.WriteLine("file path: "); //这里输入文本所在目录 例如 d:text.txt PATH = Console.ReadLine(); StreamReader r = File.OpenText(PATH); while(!r.EndOfStream){ Console.WriteLine(r.ReadLine()); } Console.ReadKey(); } }

希望本文所述对大家的C#程序设计有所帮助。

【C#控制台进行文件读写的方法】相关文章:

C# javascript 读写Cookie的方法

C#中执行批处理文件(*.bat)的方法代码

C# SkinEngine控件 给窗体添加皮肤的方法

C#中读写INI文件的方法例子

C#访问应用程序配置文件的方法

解决C#程序只允许运行一个实例的几种方法详解

C#定位txt指定行的方法小例子

C#几种截取字符串的方法小结

C#计算代码执行时间的方法

C# 如何判断两个文件内容是否相同的方法

精品推荐
分类导航