Csharp/C#教程:C#使用Streamwriter打开文件的方法分享

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

usingSystem; usingSystem.IO; publicclassKtoD1{ publicstaticvoidMain(){ stringstr; StreamWriterfstr_out; //OpenthefiledirectlyusingStreamWriter. try{ fstr_out=newStreamWriter("test.txt"); } catch(IOExceptionexc){ Console.WriteLine(exc.Message+"Cannotopenfile."); return; } Console.WriteLine("Entertext('stop'toquit)."); do{ Console.Write(":"); str=Console.ReadLine(); if(str!="stop"){ str=str+"rn";//addnewline try{ fstr_out.Write(str); }catch(IOExceptionexc){ Console.WriteLine(exc.Message+"FileError"); return; } } }while(str!="stop"); fstr_out.Close(); } }

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

您可能感兴趣的文章:C#中执行批处理文件(*.bat)的方法代码C#使用FolderBrowserDialog类实现选择打开文件夹方法详解C#实现将记事本中的代码编译成可执行文件的方法C#如何打开并读取usb的文件目录详解C#打开和关闭可执行文件

标签: write 方法 tr ite te

浅谈C++ Explicit Constructors(显式构造函数)

C/C++ 读取16进制文件的方法

上述就是C#学习教程:C#使用Streamwriter打开文件的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/906209.html

(0)
上一篇 2021年10月23日
下一篇 2021年10月23日

精彩推荐