飞秋的文件读取、写入代码
大家都知道局域網聊天發即時通訊軟件是最平常不過的事情,所以大量的導入即時通訊軟件是有利于局域網聊天的,飛秋www.freeeim.com 下載在決定一個網站的排名時,不僅要對網頁內容和結構進行分析,還圍繞網站的即時通訊軟件展開分析。對網站排名致關重要的影響因素是獲得盡可能多的高質量外部即時通訊軟件,也稱導入即時通訊軟件。
什么是導入即時通訊軟件?
?
飛秋的文件讀取、寫入代碼
文件的讀操作
?? static void Main(string[] args)
??????? {
??????????? string path = "";
??????????? Console.WriteLine("請輸入要讀取的文件的文件名,包括路徑");
??????????? path = Console.ReadLine();
??????????? if (!File.Exists(path))
??????????? {
??????????????? Console.WriteLine("文件不存在");
??????????????? return;
??????????? }
??????????? try
??????????? {
??????????????? FileStream file = new FileStream(path, FileMode.Open);
??????????????? byte[] bt = new byte[file.Length];
??????????????? file.Read(bt, 0, bt.Length);
??????????????? string str = Encoding.Default.GetString(bt);
??????????????? Console.WriteLine(str);
??????????????? Console.ReadLine();
??????????? }
??????????? catch (System.Exception e)
??????????? {
??????????????? Console.WriteLine("讀取文件出錯");
??????????? }
??????? }
?
文件的寫操作:
?????? static void Main(string[] args)
??????? {
??????????? //FileStream fs1 = File.Create("test1");
??????????? //fs1.Close();
??????????? //Console.ReadLine();
??????????? string path = "";
??????????? string content = "";
??????????? Console.WriteLine("請輸入要保存的文件的文件名,包括路徑");
??????????? path = Console.ReadLine();
??????????? Console.WriteLine("請輸入要保存的內容 ");
??????????? content = Console.ReadLine();
??????????? try
??????????? {
??????????????? FileStream file = new FileStream(path, FileMode.Create);
??????????????? byte[] bt = Encoding.UTF8.GetBytes(content);
??????????????? file.Write(bt, 0, bt.Length);
??????????????? file.Flush();
??????????? }
??????????? catch (System.Exception e)
??????????? {
??????????????? Console.WriteLine("創建或寫入文件時出錯");
????????????
??????????? }
?
?// 讀取文件流
???? static void Main(string[] args)
??????? {
??????????? Console.WriteLine("請輸入要讀取文件的文件名,包括路徑");
??????????? string path = Console.ReadLine();
??????????? if (!File.Exists(path))
??????????? {
??????????????? Console.WriteLine("文件不存在");
??????????????? return;
??????????? }
??????????? FileStream readStream = new FileStream(path, FileMode.Open);
??????????? BufferedStream readBuffered = new BufferedStream(readStream);
??????????? byte[] bt = new byte[readBuffered.Length];
??????????? readBuffered.Read(bt, 0, (int)readBuffered.Length);
??????????? Console.WriteLine(Encoding.Default.GetString(bt));
??????????? readBuffered.Close();
??????????? Console.ReadLine();
??????? }
總結
以上是生活随笔為你收集整理的飞秋的文件读取、写入代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html网页div框架代码,div层仿网
- 下一篇: 社会网络分析入门书目导读