C#掌握台停止文件讀寫的辦法。本站提示廣大學習愛好者:(C#掌握台停止文件讀寫的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#掌握台停止文件讀寫的辦法正文
本文實例講述了C#掌握台停止文件讀寫的辦法。分享給年夜家供年夜家參考。詳細以下:
C#掌握台停止文件寫入:
using System;
using System.IO;
class file1 {
public static void Main()
{
string PATH = null;
Console.WriteLine("file path: ");
//這裡輸出文本地點目次 例如 d:\text.txt
PATH = Console.ReadLine();
StreamWriter sw = new StreamWriter(PATH);
string str = null;
while(true){
str = Console.ReadLine();
if (str == "end") {
break;
}
sw.WriteLine(str);
}
sw.Close();
Console.ReadKey();
}
}
C#掌握台停止文件讀取
using System;
using System.IO;
class file1 {
public static void Main() {
string PATH = null;
Console.WriteLine("file path: ");
//這裡輸出文本地點目次 例如 d:\text.txt
PATH = Console.ReadLine();
StreamReader r = File.OpenText(PATH);
while(!r.EndOfStream){
Console.WriteLine(r.ReadLine());
}
Console.ReadKey();
}
}
願望本文所述對年夜家的C#法式設計有所贊助。