飞秋的文件读取、写入代码
大家都知道局域網(wǎng)聊天發(fā)即時(shí)通訊軟件是最平常不過(guò)的事情,所以大量的導(dǎo)入即時(shí)通訊軟件是有利于局域網(wǎng)聊天的,飛秋www.freeeim.com 下載在決定一個(gè)網(wǎng)站的排名時(shí),不僅要對(duì)網(wǎng)頁(yè)內(nèi)容和結(jié)構(gòu)進(jìn)行分析,還圍繞網(wǎng)站的即時(shí)通訊軟件展開分析。對(duì)網(wǎng)站排名致關(guān)重要的影響因素是獲得盡可能多的高質(zhì)量外部即時(shí)通訊軟件,也稱導(dǎo)入即時(shí)通訊軟件。
什么是導(dǎo)入即時(shí)通訊軟件?
?
飛秋的文件讀取、寫入代碼
文件的讀操作
?? static void Main(string[] args)
??????? {
??????????? string path = "";
??????????? Console.WriteLine("請(qǐng)輸入要讀取的文件的文件名,包括路徑");
??????????? 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("讀取文件出錯(cuò)");
??????????? }
??????? }
?
文件的寫操作:
?????? static void Main(string[] args)
??????? {
??????????? //FileStream fs1 = File.Create("test1");
??????????? //fs1.Close();
??????????? //Console.ReadLine();
??????????? string path = "";
??????????? string content = "";
??????????? Console.WriteLine("請(qǐng)輸入要保存的文件的文件名,包括路徑");
??????????? path = Console.ReadLine();
??????????? Console.WriteLine("請(qǐng)輸入要保存的內(nèi)容 ");
??????????? 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("創(chuàng)建或?qū)懭胛募r(shí)出錯(cuò)");
????????????
??????????? }
?
?// 讀取文件流
???? static void Main(string[] args)
??????? {
??????????? Console.WriteLine("請(qǐng)輸入要讀取文件的文件名,包括路徑");
??????????? 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();
??????? }
總結(jié)
以上是生活随笔為你收集整理的飞秋的文件读取、写入代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: html网页div框架代码,div层仿网
- 下一篇: 社会网络分析入门书目导读