手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#使用Streamwriter打开文件的方法
C#使用Streamwriter打开文件的方法
摘要:本文实例讲述了C#使用Streamwriter打开文件的方法。分享给大家供大家参考。具体如下:usingSystem;usingSystem...

本文实例讲述了C#使用Streamwriter打开文件的方法。分享给大家供大家参考。具体如下:

using System; using System.IO; public class KtoD1 { public static void Main() { string str; StreamWriter fstr_out; // Open the file directly using StreamWriter. try { fstr_out = new StreamWriter("test.txt"); } catch(IOException exc) { Console.WriteLine(exc.Message + "Cannot open file."); return ; } Console.WriteLine("Enter text ('stop' to quit)."); do { Console.Write(": "); str = Console.ReadLine(); if(str != "stop") { str = str + "rn"; // add newline try { fstr_out.Write(str); } catch(IOException exc) { Console.WriteLine(exc.Message + "File Error"); return ; } } } while(str != "stop"); fstr_out.Close(); } }

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

【C#使用Streamwriter打开文件的方法】相关文章:

混合语言编程—C#使用原生的Directx和OpenGL绘图的方法

c#启动EXE文件的方法实例

C#中使用split分割字符串的几种方法小结

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

C# 抓取网页内容的方法

C# DataGridView添加新行的2个方法

C#使用非托管代码直接修改字符串的方法

使用checked语句防止数据溢出的解决方法

C# 中如何利用lambda实现委托事件的挂接

C#操作注册表的方法

精品推荐
分类导航