手机
当前位置:查字典教程网 >编程开发 >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# DataGridView添加新行的2个方法

C#读写文件的方法汇总

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

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

C#图片压缩的实现方法

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

C#对XML文件的各种操作实现方法

C#技巧之快速删除bin和obj文件夹的方法

C# javascript 读写Cookie的方法

C#删除文件目录或文件的解决方法

精品推荐
分类导航