当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Write方法代码示例

本文整理汇总了C#中FileInfo.Write方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Write方法的具体用法?C# FileInfo.Write怎么用?C# FileInfo.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.Write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteTimeRefreshes

        public void WriteTimeRefreshes()
        {
            string fileName = GetTestFilePath();
            File.Create(fileName).Dispose();
            FileInfo fileInfo = new FileInfo(fileName);
            DateTime beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = new FileInfo(fileName).OpenWrite())
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            DateTime afterWrite = DateTime.Now;
            fileInfo.Refresh();
            DateTime lastWriteTime = fileInfo.LastWriteTime;
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);

            //Read from the File and test the writeTime to ensure it is unchanged
            using (Stream stream = new FileInfo(fileName).OpenRead())
            {
                stream.Read(new Byte[1], 0, 1);
            }
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime);

            //Write to the file again to test lastWriteTime can be updated again
            beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = fileInfo.Open(FileMode.Open))
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            afterWrite = DateTime.Now;
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime); //needs to be refreshed first
            fileInfo.Refresh();
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);
        }
开发者ID:rcabr,项目名称:corefx,代码行数:33,代码来源:get_LastWriteTime.cs

示例2: Write

 protected override void Write(string path, string content)
 {
     var writer = new FileInfo(path).AppendText();
     writer.Write(content);
     writer.Dispose();
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:6,代码来源:AppendText.cs

示例3: WriteFile

 private void WriteFile(StringBuilder fileContents, string fileName)
 {
     string mwlDirectory = ConfigurationManager.AppSettings["MWLDirectory"];
     string mwlFilePath = mwlDirectory + "\\" + fileName + ".xml";
     StreamWriter mwlFile = new FileInfo(mwlFilePath).CreateText();
     mwlFile.Write(fileContents.ToString());
     mwlFile.Close();
 }
开发者ID:alibinjamil,项目名称:datamedris,代码行数:8,代码来源:WorkList.aspx.cs


注:本文中的FileInfo.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。