C# File.WriteByte的代码示例

通过代码示例来学习C# File.WriteByte方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


File.WriteByte是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.WriteByte() 已经帮大家高亮显示了,大家可以重点学习File.WriteByte() 方法的写法,从而快速掌握该方法的应用。

File.WriteByte的代码示例1 - TruncatedObjectRedownloaded()

    using System.IO;

        [TestCase, Order(17)]
        public void TruncatedObjectRedownloaded()
        {
            GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "checkout " + this.Enlistment.Commitish);
            ProcessResult revParseResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "rev-parse :Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt");
            string sha = revParseResult.Output.Trim();
            sha.Length.ShouldEqual(40);
            string objectPath = Path.Combine(this.Enlistment.GetObjectRoot(this.fileSystem), sha.Substring(0, 2), sha.Substring(2, 38));
            objectPath.ShouldNotExistOnDisk(this.fileSystem);

            string corruptObjectFolderPath = Path.Combine(this.Enlistment.DotGVFSRoot, "CorruptObjects");
            int initialCorruptObjectCount = 0;
            if (this.fileSystem.DirectoryExists(corruptObjectFolderPath))
            {
                initialCorruptObjectCount = new DirectoryInfo(corruptObjectFolderPath).EnumerateFileSystemInfos().Count();
            }

            // Read a copy of TruncatedObjectRedownloaded.txt to force the object to be downloaded
            GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "rev-parse :Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded_copy.txt").Output.Trim().ShouldEqual(sha);
            string testFileContents = this.Enlistment.GetVirtualPathTo("Test_EPF_WorkingDirectoryTests", "TruncatedObjectRedownloaded_copy.txt").ShouldBeAFile(this.fileSystem).WithContents();
            objectPath.ShouldBeAFile(this.fileSystem);
            string modifedFile = "Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt";
            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.fileSystem, modifedFile);

            // Truncate the contents of objectPath
            string tempTruncatedObjectPath = objectPath + "truncated";
            FileInfo objectFileInfo = new FileInfo(objectPath);
            long objectLength = objectFileInfo.Length;
            using (FileStream objectStream = new FileStream(objectPath, FileMode.Open))
            using (FileStream truncatedObjectStream = new FileStream(tempTruncatedObjectPath, FileMode.CreateNew))
            {
                for (int i = 0; i < (objectStream.Length - 16); ++i)
                {
                    truncatedObjectStream.WriteByte((byte)objectStream.ReadByte());
                }
            }

            this.fileSystem.DeleteFile(objectPath);
            this.fileSystem.MoveFile(tempTruncatedObjectPath, objectPath);
            tempTruncatedObjectPath.ShouldNotExistOnDisk(this.fileSystem);
            objectPath.ShouldBeAFile(this.fileSystem);
            new FileInfo(objectPath).Length.ShouldEqual(objectLength - 16);

            // Windows should correct a corrupt obect
            // Read the original path and verify its contents are correct
            this.Enlistment.GetVirtualPathTo("Test_EPF_WorkingDirectoryTests", "TruncatedObjectRedownloaded.txt").ShouldBeAFile(this.fileSystem).WithContents(testFileContents);

            // Confirm there's a new item in the corrupt objects folder
            corruptObjectFolderPath.ShouldBeADirectory(this.fileSystem).WithItems().Count().ShouldEqual(initialCorruptObjectCount + 1);

            // File should not be in ModifiedPaths.dat
            GVFSHelpers.ModifiedPathsShouldNotContain(this.Enlistment, this.fileSystem, "Test_EPF_WorkingDirectoryTests/TruncatedObjectRedownloaded.txt");
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:55,代码来源:WorkingDirectoryTests.cs

在TruncatedObjectRedownloaded()方法中,File的代码示例类中的WriteByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.WriteByte的代码示例2 - WriteHeaderBlock()

    using System.IO;

        /// 
        /// Writes the header block of the animated gif to the stream.
        /// 
        /// The source gif.
        /// The width of the image.
        /// The height of the image.
        private void WriteHeaderBlock(Stream sourceGif, int width, int height)
        {
            // File Header signature and version.
            this.imageStream.Write(FileType, 0, FileType.Length);

            // Write the logical screen descriptor.
            this.WriteShort(width); // Initial Logical Width
            this.WriteShort(height); // Initial Logical Height

            // Read the global color table info.
            sourceGif.Position = SourceGlobalColorInfoPosition;
            this.WriteByte(sourceGif.ReadByte());

            this.WriteByte(255); // Background Color Index
            this.WriteByte(0); // Pixel aspect ratio
            this.WriteColorTable(sourceGif);

            // Application Extension Header
            int count = this.repeatCount;
            if (count != 1)
            {
                // 0 means loop indefinitely. count is set as play n + 1 times.
                count = Math.Max(0, count - 1);
                this.WriteShort(ApplicationExtensionBlockIdentifier);
                this.WriteByte(ApplicationBlockSize);

                this.imageStream.Write(ApplicationIdentification, 0, ApplicationIdentification.Length);
                this.WriteByte(3); // Application block length
                this.WriteByte(1);
                this.WriteShort(count); // Repeat count for images.

                this.WriteByte(0); // Terminator
            }
        }
    

开发者ID:JimBobSquarePants,项目名称:ImageProcessor,代码行数:42,代码来源:GifEncoder.cs

在WriteHeaderBlock()方法中,File的代码示例类中的WriteByte的代码示例方法一共出现了7次, 见黄色背景高亮显示的地方,欢迎大家点赞

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