C# File.WriteAllBytes的代码示例

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

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


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

File.WriteAllBytes的代码示例1 - GitRequestsReplacementForAllNullObject()

    using System.IO;

        [TestCase]
        public void GitRequestsReplacementForAllNullObject()
        {
            Action allNullObject = (string objectPath) =>
            {
                FileInfo objectFileInfo = new FileInfo(objectPath);
                File.WriteAllBytes(objectPath, Enumerable.Repeat(0, (int)objectFileInfo.Length).ToArray());
            };

            this.RunGitDiffWithCorruptObject(allNullObject);
            this.RunGitCatFileWithCorruptObject(allNullObject);
            this.RunGitResetHardWithCorruptObject(allNullObject);
            this.RunGitCheckoutOnFileWithCorruptObject(allNullObject);
        }
    

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

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

File.WriteAllBytes的代码示例2 - AllNullObjectRedownloaded()

    using System.IO;

        [TestCase, Order(16)]
        public void AllNullObjectRedownloaded()
        {
            GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "checkout " + this.Enlistment.Commitish);
            ProcessResult revParseResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "rev-parse :Test_EPF_WorkingDirectoryTests/AllNullObjectRedownloaded.txt");
            string sha = revParseResult.Output.Trim();
            sha.Length.ShouldEqual(40);

            // Ensure SHA path is lowercase for case-sensitive filesystems
            string objectPathSha = FileSystemHelpers.CaseSensitiveFileSystem ? sha.ToLower() : sha;
            string objectPath = Path.Combine(this.Enlistment.GetObjectRoot(this.fileSystem), objectPathSha.Substring(0, 2), objectPathSha.Substring(2, 38));
            objectPath.ShouldNotExistOnDisk(this.fileSystem);

            // At this point there should be no corrupt objects
            string corruptObjectFolderPath = Path.Combine(this.Enlistment.DotGVFSRoot, "CorruptObjects");
            corruptObjectFolderPath.ShouldNotExistOnDisk(this.fileSystem);

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

            // Set the contents of objectPath to all NULL
            FileInfo objectFileInfo = new FileInfo(objectPath);
            File.WriteAllBytes(objectPath, Enumerable.Repeat(0, (int)objectFileInfo.Length).ToArray());

            // Read the original path and verify its contents are correct
            this.Enlistment.GetVirtualPathTo("Test_EPF_WorkingDirectoryTests", "AllNullObjectRedownloaded.txt").ShouldBeAFile(this.fileSystem).WithContents(testFileContents);

            // Confirm there's a new item in the corrupt objects folder
            corruptObjectFolderPath.ShouldBeADirectory(this.fileSystem);
            FileSystemInfo badObject = corruptObjectFolderPath.ShouldBeADirectory(this.fileSystem).WithOneItem();
            (badObject as FileInfo).ShouldNotBeNull().Length.ShouldEqual(objectFileInfo.Length);
        }
    

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

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

File.WriteAllBytes的代码示例3 - Application_Startup()

    using System.IO;

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            splashscreen = new SplashScreen();
            splashscreen.Show();
            App.DoEvents();

            byte[] msiData = WpfSetup.Properties.Resources.MyProduct_msi;
            MsiFile = Path.Combine(Path.GetTempPath(), "MyProduct.msi");

            if (!File.Exists(MsiFile) || new FileInfo(MsiFile).Length != msiData.Length)
                File.WriteAllBytes(MsiFile, msiData);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:16,代码来源:App.xaml.cs

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

File.WriteAllBytes的代码示例4 - EnsureFileExists()

    using System.IO;

        /// 
        /// Ensures the file exists.
        /// 
        /// The path.
        /// 
        public static string EnsureFileExists(this string path)
        {
            var filePath = path.PathGetFullPath();

            if (!IO.File.Exists(filePath))
            {
                filePath.PathGetDirName().EnsureDirExists();
                IO.File.WriteAllBytes(filePath, new byte[0]);
            }
            return path;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:18,代码来源:Extensions.cs

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

File.WriteAllBytes的代码示例5 - UserOrDefaultContentOf()

    using System.IO;

        internal static string UserOrDefaultContentOf(string extenalFilePath, string srcDir, string outDir, string fileName, object defaultContent)
        {
            string extenalFile = Utils.PathCombine(srcDir, extenalFilePath);

            if (extenalFilePath.IsNotEmpty()) //important to test before PathComibed
                return extenalFile;

            var file = Path.Combine(outDir, fileName);

            if (defaultContent is byte[])
                io.File.WriteAllBytes(file, (byte[])defaultContent);
            else if (defaultContent is Bitmap)
                ((Bitmap)defaultContent).Save(file, ImageFormat.Png);
            else if (defaultContent is string)
                io.File.WriteAllBytes(file, ((string)defaultContent).GetBytes());
            else if (defaultContent == null)
                return "";
            else
                throw new Exception("Unsupported ManagedUI resource type.");

            Compiler.TempFiles.Add(file);
            return file;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:25,代码来源:UIExtensions.cs

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

File.WriteAllBytes的代码示例6 - GenerateJsonFromFile()

    using System.IO;

        private static void GenerateJsonFromFile(string file, string fbs)
        {
            var fbsName = fbs + ".fbs";
            var fbsPath = Path.Combine(FlatPath, fbsName);
            Directory.CreateDirectory(FlatPath);
            if (!File.Exists(fbsPath))
                File.WriteAllBytes(fbsPath, GetSchema(fbs));

            var fileName = Path.GetFileName(file);
            var filePath = Path.Combine(FlatPath, fileName);
            File.Copy(file, filePath, true);

            var args = GetArgumentsDeserialize(fileName, fbsName);
            RunFlatC(args);
            File.Delete(filePath);
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:18,代码来源:FlatBufferConverter.cs

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

File.WriteAllBytes的代码示例7 - exportToolStripMenuItem_Click()

    
        private void exportToolStripMenuItem_Click(object sender, EventArgs e) {
            Dictionary files = new Dictionary();

            foreach (ListViewItem item in listView1.SelectedItems) {
                var bxlan = item.Tag as BxlanHeader;
                var fileFormat = bxlan.FileInfo;
                //Check parent archive for raw data to export
                if (!fileFormat.CanSave && fileFormat.IFileInfo.ArchiveParent != null)
                {
                    foreach (var file in fileFormat.IFileInfo.ArchiveParent.Files)
                    {
                        if (file.FileName == fileFormat.FileName) {
                            files.Add(file.FileName, file.FileData);
                        }
                    }
                }
                else
                {
                    var mem = new System.IO.MemoryStream();
                    bxlan.FileInfo.Save(mem);
                    files.Add(fileFormat.FileName, mem.ToArray());
                }
            }

            if (files.Count == 1)
            {
                string name = files.Keys.FirstOrDefault();

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName = System.IO.Path.GetFileName(name);
                sfd.DefaultExt = System.IO.Path.GetExtension(name);

                if (sfd.ShowDialog() == DialogResult.OK) {
                    System.IO.File.WriteAllBytes(sfd.FileName, files.Values.FirstOrDefault());
                }
            }
            if (files.Count > 1)
            {
                FolderSelectDialog dlg = new FolderSelectDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    foreach (var file in files) {
                        string name = System.IO.Path.GetFileName(file.Key);
                        System.IO.File.WriteAllBytes($"{dlg.SelectedPath}/{name}", file.Value);
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:49,代码来源:LayoutAnimList.cs

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

File.WriteAllBytes的代码示例8 - DecompileShader()

    using System.IO;

        public static string DecompileShader(NswShaderType shaderType, byte[] Data, ulong Address = 0)
        {
            if (!Directory.Exists("temp"))
                Directory.CreateDirectory("temp");

            if (!Directory.Exists("ShaderTools"))
                Directory.CreateDirectory("ShaderTools");

            //     File.WriteAllBytes("temp/shader1.bin", Utils.CombineByteArray(data.ToArray()));
            File.WriteAllBytes("temp/shader1.bin", Data);

            if (!File.Exists($"{Runtime.ExecutableDir}/ShaderTools/Ryujinx.ShaderTools.exe"))
            {
                MessageBox.Show("No shader decompiler found in ShaderTools. If you want to decompile a shader, you can use Ryujinx's ShaderTools.exe and put in the ShaderTools folder of the toolbox.");
                return "";
            }

            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = "ShaderTools/Ryujinx.ShaderTools.exe";
            start.WorkingDirectory = Runtime.ExecutableDir;
            start.Arguments = $"{Utils.AddQuotesIfRequired("temp/shader1.bin")}";
            start.UseShellExecute = false;
            start.RedirectStandardOutput = true;
            start.CreateNoWindow = true;
            start.WindowStyle = ProcessWindowStyle.Hidden;
            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    try
                    {
                        return reader.ReadToEnd();
                    }
                    catch (Exception ex)
                    {
                        Toolbox.Library.Forms.STErrorDialog.Show("Failed to decompile shader!", "Shader Tools", ex.ToString());
                        return "";
                    }
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:43,代码来源:NSWShaderDecompile.cs

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

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