C# File.ReadAllBytes的代码示例
通过代码示例来学习C# File.ReadAllBytes方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
File.ReadAllBytes是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.ReadAllBytes() 已经帮大家高亮显示了,大家可以重点学习File.ReadAllBytes() 方法的写法,从而快速掌握该方法的应用。
File.ReadAllBytes的代码示例1 - CloneAndMount()
using System.IO; public void CloneAndMount(bool skipPrefetch) { this.gvfsProcess.Clone(this.RepoUrl, this.Commitish, skipPrefetch); GitProcess.Invoke(this.RepoRoot, "checkout " + this.Commitish); GitProcess.Invoke(this.RepoRoot, "branch --unset-upstream"); GitProcess.Invoke(this.RepoRoot, "config core.abbrev 40"); GitProcess.Invoke(this.RepoRoot, "config user.name \"Functional Test User\""); GitProcess.Invoke(this.RepoRoot, "config user.email \"functional@test.com\""); // If this repository has a .gitignore file in the root directory, force it to be // hydrated. This is because if the GitStatusCache feature is enabled, it will run // a "git status" command asynchronously, which will hydrate the .gitignore file // as it reads the ignore rules. Hydrate this file here so that it is consistently // hydrated and there are no race conditions depending on when / if it is hydrated // as part of an asynchronous status scan to rebuild the GitStatusCache. string rootGitIgnorePath = Path.Combine(this.RepoRoot, ".gitignore"); if (File.Exists(rootGitIgnorePath)) { File.ReadAllBytes(rootGitIgnorePath); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:24,代码来源:GVFSFunctionalTestEnlistment.cs
在CloneAndMount()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例2 - OverwritingIndexShouldFail()
using System.IO; private void OverwritingIndexShouldFail(string testFilePath) { string indexPath = this.Enlistment.GetVirtualPathTo(".git", "index"); this.Enlistment.WaitForBackgroundOperations(); byte[] indexContents = File.ReadAllBytes(indexPath); string testFileContents = "OverwriteIndexTest"; this.fileSystem.WriteAllText(testFilePath, testFileContents); this.Enlistment.WaitForBackgroundOperations(); this.RenameAndOverwrite(testFilePath, indexPath).ShouldBeFalse("GVFS should prevent renaming on top of index when GVFSLock is not held"); byte[] newIndexContents = File.ReadAllBytes(indexPath); indexContents.SequenceEqual(newIndexContents).ShouldBeTrue("Index contenst should not have changed"); this.fileSystem.DeleteFile(testFilePath); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:21,代码来源:GVFSLockTests.cs
在OverwritingIndexShouldFail()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例3 - CanReadHydratedPlaceholderInParallel()
using System.IO; [TestCase, Order(2)] public void CanReadHydratedPlaceholderInParallel() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string fileName = Path.Combine("GVFS", "GVFS.FunctionalTests", "Tests", "LongRunningEnlistment", "WorkingDirectoryTests.cs"); string virtualPath = this.Enlistment.GetVirtualPathTo(fileName); virtualPath.ShouldBeAFile(fileSystem); // Not using the runner because reading specific bytes isn't common // Can't use ReadAllText because it will remove some bytes that the stream won't. byte[] actualContents = File.ReadAllBytes(virtualPath); Thread[] threads = new Thread[4]; // Readers bool keepRunning = true; for (int i = 0; i < threads.Length; ++i) { int myIndex = i; threads[i] = new Thread(() => { // Create random seeks (seeded for repeatability) Random randy = new Random(myIndex); // Small buffer so we hit the drive a lot. // Block larger than the buffer to hit the drive more const int SmallBufferSize = 128; const int LargerBlockSize = SmallBufferSize * 10; using (Stream reader = new FileStream(virtualPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, SmallBufferSize, false)) { while (keepRunning) { byte[] block = new byte[LargerBlockSize]; // Always try to grab a full block (easier for asserting) int position = randy.Next((int)reader.Length - block.Length - 1); reader.Position = position; reader.Read(block, 0, block.Length).ShouldEqual(block.Length); block.ShouldEqual(actualContents, position, block.Length); } } }); threads[i].Start(); } Thread.Sleep(2500); keepRunning = false; for (int i = 0; i < threads.Length; ++i) { threads[i].Join(); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:58,代码来源:MultithreadedReadWriteTests.cs
在CanReadHydratedPlaceholderInParallel()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例4 - ValidateUITextFile()
///
/// Validates the UI text file (localization file) for being compatible with ManagedUI. /// /// The file. /// if set totrue [throw on error]. ///public static bool ValidateUITextFile(string file, bool throwOnError = true) { try { var data = new ResourcesData(); data.InitFromWxl(System.IO.File.ReadAllBytes(file)); } catch (Exception e) { //may need to do extra logging; not important for now if (throwOnError) throw new Exception("Localization file is incompatible with ManagedUI.", e); else return false; } return true; }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:24,代码来源:ManagedUI.cs
在ValidateUITextFile()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例5 - SaveTex2()
using System.IO; private void SaveTex2(string fileName) { bool Compressed = fileName.EndsWith("sbfres"); byte[] data; if (Compressed) data = EveryFileExplorer.YAZ0.Decompress(fileName); else data = File.ReadAllBytes(fileName); ResU.ResFile resFileTex2 = new ResU.ResFile(new MemoryStream(data)); foreach (BFRESGroupNode group in Nodes) { if (group.Type != BRESGroupType.Textures) return; foreach (FTEX tex in group.Nodes) { if (resFileTex2.Textures.ContainsKey(tex.Text)) { resFileTex2.Textures[tex.Text].MipData = tex.texture.MipData; resFileTex2.Textures[tex.Text].MipOffsets = tex.texture.MipOffsets; resFileTex2.Textures[tex.Text].MipCount = tex.texture.MipCount; } } } MemoryStream mem2 = new MemoryStream(); resFileTex2.Save(mem2); SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = FileName + "NewTex2.sbfres"; List
formats = new List (); formats.Add(this); sfd.Filter = Utils.GetAllFilters(formats); if (sfd.ShowDialog() == DialogResult.OK) STFileSaver.SaveFileFormat(mem2.ToArray(), Compressed,new Yaz0(), 0, sfd.FileName); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:43,代码来源:BFRES.cs
在SaveTex2()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例6 - ReplaceAllAction()
using System.IO; private void ReplaceAllAction(object sender, EventArgs args) { FolderSelectDialog folderDialog = new FolderSelectDialog(); if (folderDialog.ShowDialog() != DialogResult.OK) return; foreach (var folder in Directory.GetDirectories(folderDialog.SelectedPath)) { foreach (var file in Directory.GetFiles(folder)) { var fileInfo = ArchiveFile.Files.FirstOrDefault(x => Path.GetFileName(x.FileName).Contains(Path.GetFileName(file))); if (fileInfo != null) fileInfo.FileData = File.ReadAllBytes(file); } } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:20,代码来源:QuickAccessFolder.cs
在ReplaceAllAction()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例7 - DecompressData()
using System.IO; private static byte[] DecompressData(FileReader reader, string FileName, byte[] data) { reader.ByteOrder = ByteOrder.BigEndian; reader.Position = 0; uint MagicHex = reader.ReadUInt32(); string Magic = reader.ReadMagic(0, 4); reader.Position = 0; if (Magic == "Yaz0") { if (data != null) return EveryFileExplorer.YAZ0.Decompress(data); else return EveryFileExplorer.YAZ0.Decompress(FileName); } if (MagicHex == 0x28B52FFD || MagicHex == 0xFD2FB528) { if (data != null) return Zstb.SDecompress(data); else return Zstb.SDecompress(File.ReadAllBytes(FileName)); } return data; }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:27,代码来源:STFileLoader.cs
在DecompressData()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.ReadAllBytes的代码示例8 - GetExternalDictionaries()
using System.IO; static byte[] GetExternalDictionaries() { byte[] dictionary = new byte[0]; var userDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SwitchToolbox"); if (!Directory.Exists(userDir)) Directory.CreateDirectory(userDir); //Create folder for TOTK contents if it does not exist if (!Directory.Exists(Path.Combine(userDir, "TOTK"))) Directory.CreateDirectory(Path.Combine(userDir, "TOTK")); string folder = Path.Combine(userDir, "TOTK", "ZstdDictionaries"); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); void TransferZDic(string path) { //Check if old directory contains the file and move it string fileOld = Path.Combine(Runtime.ExecutableDir, "Lib", "ZstdDictionaries", path); string fileNew = Path.Combine(folder, path); if (!File.Exists(fileNew) && File.Exists(fileOld)) { File.Move(fileOld, fileNew); } } TransferZDic("bcett.byml.zsdic"); TransferZDic("pack.zsdic"); TransferZDic("zs.zsdic"); if (Directory.Exists(folder)) { void CheckZDic(string fileName, string expectedExtension) { //Dictionary already set if (dictionary.Length != 0) return; string zDictPath = Path.Combine(folder, fileName); //Then check if the input file uses the expected extension if (File.Exists(zDictPath) && fileNameTemp.EndsWith(expectedExtension)) dictionary = File.ReadAllBytes(zDictPath); } //Order matters, zs must go last CheckZDic("bcett.byml.zsdic", "bcett.byml.zs" ); CheckZDic("pack.zsdic", "pack.zs" ); CheckZDic("zs.zsdic", ".zs" ); } return dictionary; }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:53,代码来源:Zstb.cs
在GetExternalDictionaries()方法中,File的代码示例类中的ReadAllBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的File.ReadAllBytes方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。