c# 文件流读写文件
生活随笔
收集整理的這篇文章主要介紹了
c# 文件流读写文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;namespace 文件流
{class Program{static void Main(string[] args){//C#文件流寫文件,默認追加FileMode.Appendstring msg = "ok";byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg);using (FileStream fsWrite = new FileStream(@"C:\1.txt", FileMode.Append)){fsWrite.Write(myByte, 0, myByte.Length);};//c#文件流讀文件using (FileStream fsRead = new FileStream(@"C:\1.txt", FileMode.Open)){int fsLen = (int)fsRead.Length;byte[] heByte = new byte[fsLen];int r = fsRead.Read(heByte, 0, heByte.Length);string myStr = System.Text.Encoding.UTF8.GetString(heByte);Console.WriteLine(myStr);Console.ReadKey();}}}
}
轉載于:https://www.cnblogs.com/dyee/archive/2012/06/07/2540517.html
總結
以上是生活随笔為你收集整理的c# 文件流读写文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是对象?——摘自《设计模式精解》(熊
- 下一篇: Hadoop配置机架感知(python脚