时间:2021-05-20
本文实例讲述了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 + "\r\n"; // add newline try { fstr_out.Write(str); } catch(IOException exc) { Console.WriteLine(exc.Message + "File Error"); return ; } } } while(str != "stop"); fstr_out.Close(); }}希望本文所述对大家的C#程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了C#使用StreamWriter写入文件的方法。分享给大家供大家参考。具体实现方法如下:usingSystem;usingSystem.Colle
本文所述实例为C#运用FileInfo类实现拷贝文件的方法,程序中C#首先创建一个StreamWriter对象writer,它向FileInfo的实例srcFi
本文具体给出了C#常用的文件操作方法,包括C#追加文件,C#拷贝文件,C#删除文件,C#移动文件,C#创建目录。(1)C#追加文件StreamWritersw=
本文实例讲述了C#获取并修改文件扩展名的方法。分享给大家供大家参考。具体分析如下:这里使用C#编程的方法改变文件扩展名的文件,必须使用Path类。Path类用来
本文实例讲述了C#逐行读取文件的方法。分享给大家供大家参考。具体如下:这里使用C#逐行读取文件,对于大文件的读取非常有用。StreamReadersr=newS