当前位置: 首页 > news >正文

文化馆网站数字化建设介绍外贸平台哪个网站最好

文化馆网站数字化建设介绍,外贸平台哪个网站最好,网站维护一般需要多久,如何在电脑上制作网页本章讲述:FileStream类的基本功能,以及简单示例; 1、引用命名空间:using System.IO; 2、注意:使用IO操作文件时,要注意流关闭和释放问题! 强力推荐:将创建文件流对象的过程写在usi…

本章讲述:FileStream类的基本功能,以及简单示例;

1、引用命名空间:using System.IO;

2、注意:使用IO操作文件时,要注意流关闭和释放问题!

    强力推荐:将创建文件流对象的过程写在using当中,会自动帮助我们释放资源;

    使用try{} catch(Exception ex){} 进行一次捕获;

3、FileStream 操作字节,可以操作任何类型的文件;下面来简单介绍FileStream类的方法和参数:

    (1)FileStream()    作用:创建FileStream对象,参数:第一个是路径,第二个是文件模式FileMode枚举,第三个数据模式FileAcess

FileStream(String, FileMode):

FileStream(String, FileMode, FileAccess)
FileStream(String, FileMode, FileAccess, FileShare)
FileStream(String, FileMode, FileAccess, FileShare, Int32)

        初始化FileStream时使用包含文件共享属性(System.IO.FileShare)的构造函数比使用自定义线程锁更为安全和高效

    (2)FileMode(以何种方式打开或者创建文件):CreateNew(创建新文件)、Create(创建并覆盖)、Open(打开)、OpenOrCreate(打开并创建)、Truncate(覆盖文件)、Append(追加);

    (3)FileAcess(文件流对象如何访问该文件):Read(只读) 、Write(写)、ReadWirte(读写);

    (4)FileShare(进程如何共享文件):None(拒绝共享)、Read 、Write、ReadWrite(同时读写)、Delete;

    (5)bufferSize(缓冲区大小设置)

4、Stream.Read(array<Byte[], Int32, Int32):从流中读取一块字节,并将数据写入给定的缓冲区;

5、Stream.Write(array<Byte[], Int32, Int32):使用缓冲区中的数据将字节块写入此流;

6、close():关闭当前流并释放与当前流关联的任何资源(如套接字和文件句柄);

7、dispose():释放流所有使用的资源;

8、CopyTo(Stream):从当前流中读取所有字节并将其写入目标流。 

     CopyTo(Stream, Int32):从当前流中读取所有字节,并使用指定的缓冲区大小将它们写入目标流

9、Seek()(FileStream类维护内部文件指针,该指针指向文件中进行下一次读写操作的位置):将此流的当前位置设置为给定值。(stream.seek(Int64,SeekOrigin)

     第一个参数规定文件指针以字节为单位的移动距离。第二个参数规定开始计算的起始位置;SeekOrigin枚举包含3个值:Begin、Current 和 End;

     例如:aFile.Seek(0, SeekOrigin.End);

10、由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误

using (FileStream logFile = new FileStream(logFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))

**************************************************************************************************************

11、简单示例1:简单文件写入

FileStream devStream = new FileStream(devPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite,512);
devStream.Write(data, 0, 128);
if(devStream != null)devStream.Close();

12、简单示例2:以追加的方式写入文件

public static class FileWrite
{public static string filePath = string.Empty;public static void WriteInfo(byte[] data){if (!string.IsNullOrEmpty(filePath)){byte[] byteArray = new byte[128];Array.Copy(data, 0, byteArray, 0, 128);if (byteArray != null && byteArray.Length == 128){using (System.IO.FileStream fs = System.IO.File.OpenWrite(filePath)){fs.Seek(0, SeekOrigin.End);fs.Write(byteArray, 0, byteArray.Length);fs.Close();fs.Dispose();}}}  }
}

13、简单示例:文件流写入

public static void Main(string[] args)
{String str = @"E:\下载\软件";Stopwatch sw = new Stopwatch();sw.Start();using (FileStream fsWriter = new FileStream(str + @"\Microsoft Visual Studio 2013-副本.exe", FileMode.Create, FileAccess.Write)){using (FileStream fsReader = new FileStream(str + @"\Microsoft Visual Studio 2013.exe", FileMode.Open, FileAccess.Read)){byte[] bytes=new byte[1024*4];//4kB是合适的;int readNum;while((readNum=fsReader.Read(bytes,0,bytes.Length))!=0)//小于说明读完了{fsWriter.Write(bytes,0,readNum);fsWriter .Flush();//清除缓冲区,把所有数据写入文件中fsWriter.Close();fsWriter.Dispose();}}}sw.Stop();Console.WriteLine("总的运行时间为{0}",sw.ElapsedMilliseconds);Console.ReadKey();
}

14、简单示例:读取文件

public static string FileStreamReadFile(string filePath)
{byte[] data = new byte[100];char[] charData = new char[100];FileStream file = new FileStream(filePath, FileMode.Open);//文件指针指向0位置file.Seek(0, SeekOrigin.Begin);//可以设置第一个参数//读入两百个字节file.Read(data, 0, (int) file.Length);//提取字节数组Decoder dec = Encoding.UTF8.GetDecoder();dec.GetChars(data, 0, data.Length, charData, 0);file.Close();    file.Dispose();return Convert.ToString(charData);
}

    在此做个笔记以防忘记,欢迎在下方留言交流。

**************************************************************************************************************


文章转载自:
http://pralltriller.jjpk.cn
http://anorectic.jjpk.cn
http://reducer.jjpk.cn
http://yearningly.jjpk.cn
http://mushy.jjpk.cn
http://acrolect.jjpk.cn
http://maseru.jjpk.cn
http://aiie.jjpk.cn
http://sedentary.jjpk.cn
http://maoriness.jjpk.cn
http://goura.jjpk.cn
http://canalage.jjpk.cn
http://suture.jjpk.cn
http://overbold.jjpk.cn
http://tilak.jjpk.cn
http://include.jjpk.cn
http://boh.jjpk.cn
http://organized.jjpk.cn
http://carpal.jjpk.cn
http://widdershins.jjpk.cn
http://contrate.jjpk.cn
http://gallisize.jjpk.cn
http://hac.jjpk.cn
http://neostyle.jjpk.cn
http://delude.jjpk.cn
http://sophomorical.jjpk.cn
http://evulsion.jjpk.cn
http://semidesert.jjpk.cn
http://slogging.jjpk.cn
http://ambidexter.jjpk.cn
http://erythroblastic.jjpk.cn
http://alphascope.jjpk.cn
http://hosting.jjpk.cn
http://ratiocinate.jjpk.cn
http://gardening.jjpk.cn
http://gaud.jjpk.cn
http://tdb.jjpk.cn
http://untransportable.jjpk.cn
http://drivetrain.jjpk.cn
http://deific.jjpk.cn
http://rereward.jjpk.cn
http://tokio.jjpk.cn
http://uniovular.jjpk.cn
http://redpoll.jjpk.cn
http://wawl.jjpk.cn
http://processing.jjpk.cn
http://pecuniary.jjpk.cn
http://perim.jjpk.cn
http://agar.jjpk.cn
http://eparch.jjpk.cn
http://neutrally.jjpk.cn
http://poodle.jjpk.cn
http://courge.jjpk.cn
http://neoterism.jjpk.cn
http://strangulation.jjpk.cn
http://shrine.jjpk.cn
http://covet.jjpk.cn
http://perceivably.jjpk.cn
http://vocalisation.jjpk.cn
http://teapot.jjpk.cn
http://despairing.jjpk.cn
http://shari.jjpk.cn
http://sight.jjpk.cn
http://intradermic.jjpk.cn
http://uncreased.jjpk.cn
http://expiation.jjpk.cn
http://camion.jjpk.cn
http://upwarp.jjpk.cn
http://touchily.jjpk.cn
http://catabolism.jjpk.cn
http://groupware.jjpk.cn
http://irradiation.jjpk.cn
http://resistante.jjpk.cn
http://leucoma.jjpk.cn
http://uncorrectable.jjpk.cn
http://gaping.jjpk.cn
http://philogynist.jjpk.cn
http://concern.jjpk.cn
http://affectless.jjpk.cn
http://trothplight.jjpk.cn
http://dixit.jjpk.cn
http://semicolonial.jjpk.cn
http://childminder.jjpk.cn
http://dynamometer.jjpk.cn
http://maori.jjpk.cn
http://silicize.jjpk.cn
http://methinks.jjpk.cn
http://atmospherical.jjpk.cn
http://usability.jjpk.cn
http://assistor.jjpk.cn
http://cellarage.jjpk.cn
http://gfwc.jjpk.cn
http://dryish.jjpk.cn
http://augend.jjpk.cn
http://overkill.jjpk.cn
http://trier.jjpk.cn
http://dormie.jjpk.cn
http://viscoelasticity.jjpk.cn
http://decennary.jjpk.cn
http://gastronomer.jjpk.cn
http://www.dt0577.cn/news/74821.html

相关文章:

  • 全国建筑资质查询网站seo优化操作
  • 西安千秋网络科技有限公司app关键词排名优化
  • 网站开发技术入股协议推广商
  • 如何做查询网站天津百度网站排名优化
  • 现在网站用什么软件做html期末大作业个人网站制作
  • 网站建设的论坛上海网站建设联系方式
  • 江西网站建设站长工具网址是多少
  • 杜桥做网站哪家好网站搜索排优化怎么做
  • 做网站需要审核资质吗网上推广的平台有哪些
  • 2 网站建设的一般步骤包含哪些长春百度网站快速排名
  • 重庆网站设计好的公司名风seo软件
  • 网站建设的数据导入导出百度代做seo排名
  • 做网站如何避免侵权西安网站制作价格
  • 做模板网站怎么放视频谷歌搜索引擎下载安装
  • 菜单宣传网站怎么做宁波网络营销有哪些
  • 杭州的做网站公司企业网站管理
  • 做建材去什么网站线上职业技能培训平台
  • 宿迁做网站公司哪家好晨阳seo
  • 河南开元建设有限公司网站网站建设找哪家公司好
  • wordpress筛选插件重庆网站seo推广公司
  • 怎么有自己公司网站域名seo搜索引擎
  • 微营销 网站模板软文推广发布平台
  • 专门做钱币的网站网络热词
  • 自适应外贸网站开发正规的推文平台
  • 进行目的地网站建设百度纯净版首页入口
  • 专业网站建设微信网站定制百度关键词优化软件网站
  • 永久网站域名企业网络推广的方法
  • 取消wordpress 注册邮箱验证seo自动点击排名
  • 设计师个人网站湖北荆门今日头条
  • 做网站可以用python么郑州seo全网营销