C#使用Streamwriter打開(kāi)文件的方法
更新時(shí)間:2015年04月08日 14:31:47 作者:heishui
這篇文章主要介紹了C#使用Streamwriter打開(kāi)文件的方法,涉及C#操作文件的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#使用Streamwriter打開(kāi)文件的方法。分享給大家供大家參考。具體如下:
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();
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#鍵盤輸入回車鍵實(shí)現(xiàn)點(diǎn)擊按鈕效果的方法
這篇文章主要介紹了C#鍵盤輸入回車鍵實(shí)現(xiàn)點(diǎn)擊按鈕效果的方法,可實(shí)現(xiàn)用回車鍵代替點(diǎn)擊按鈕的功能,是非常實(shí)用的技巧,需要的朋友可以參考下
2014-09-09
c# 幾種常見(jiàn)的加密方法的實(shí)現(xiàn)
這篇文章主要介紹了c# 幾種常見(jiàn)的加密方法的實(shí)現(xiàn),幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
2020-12-12
C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式
這篇文章主要介紹了C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
2023-03-03
C#實(shí)現(xiàn)簡(jiǎn)單的計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)單的計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2022-01-01
Unity Shader實(shí)現(xiàn)動(dòng)態(tài)過(guò)場(chǎng)切換圖片效果
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)動(dòng)態(tài)過(guò)場(chǎng)切換圖片效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2021-07-07 
