C# StreamWriter.Flush的代码示例
通过代码示例来学习C# StreamWriter.Flush方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
StreamWriter.Flush是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamWriter.Flush() 已经帮大家高亮显示了,大家可以重点学习StreamWriter.Flush() 方法的写法,从而快速掌握该方法的应用。
StreamWriter.Flush的代码示例1 - CanDeleteHydratedFilesWhileTheyAreOpenForWrite()
using System.IO; [TestCase] public void CanDeleteHydratedFilesWhileTheyAreOpenForWrite() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string fileName = "GVFS.sln"; string virtualPath = this.Enlistment.GetVirtualPathTo(fileName); virtualPath.ShouldBeAFile(fileSystem); using (Stream stream = new FileStream(virtualPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete)) using (StreamReader reader = new StreamReader(stream)) { // First line is empty, so read two lines string line = reader.ReadLine() + reader.ReadLine(); line.Length.ShouldNotEqual(0); File.Delete(virtualPath); this.VerifyExistenceAfterDeleteWhileOpen(virtualPath, fileSystem); using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("newline!"); writer.Flush(); this.VerifyExistenceAfterDeleteWhileOpen(virtualPath, fileSystem); } } virtualPath.ShouldNotExistOnDisk(fileSystem); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:31,代码来源:BasicFileSystemTests.cs
在CanDeleteHydratedFilesWhileTheyAreOpenForWrite()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例2 - TryWriteTempFile()
using System.IO; ///
/// Attempts to write all data lines to tmp file /// /// Method that returns the dataLines to write as an IEnumerable /// Output parameter that's set when TryWriteTempFile catches a non-fatal exception ///True if the write succeeded and false otherwise ///If a fatal exception is encountered while trying to write the temp file, this method will not catch it. private bool TryWriteTempFile(Func> getDataLines, out Exception handledException) { handledException = null; try { using (Stream tempFile = this.fileSystem.OpenFileStream(this.tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None, callFlushFileBuffers: true)) using (StreamWriter writer = new StreamWriter(tempFile)) { foreach (string line in getDataLines()) { writer.Write(line + NewLine); } tempFile.Flush(); } return true; } catch (IOException e) { handledException = e; return false; } catch (UnauthorizedAccessException e) { handledException = e; return false; } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:39,代码来源:FileBasedCollection.cs
在TryWriteTempFile()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例3 - TryWriteTempFileAndRename()
using System.IO; public bool TryWriteTempFileAndRename(string destinationPath, string contents, out Exception handledException) { handledException = null; string tempFilePath = destinationPath + ".temp"; string parentPath = Path.GetDirectoryName(tempFilePath); this.CreateDirectory(parentPath); try { using (Stream tempFile = this.OpenFileStream(tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None, callFlushFileBuffers: true)) using (StreamWriter writer = new StreamWriter(tempFile)) { writer.Write(contents); tempFile.Flush(); } this.MoveAndOverwriteFile(tempFilePath, destinationPath); return true; } catch (Win32Exception e) { handledException = e; return false; } catch (IOException e) { handledException = e; return false; } catch (UnauthorizedAccessException e) { handledException = e; return false; } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:38,代码来源:PhysicalFileSystem.cs
在TryWriteTempFileAndRename()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例4 - WriteRegistry()
using System.IO; private void WriteRegistry(Dictionary
registry) { string tempFilePath = Path.Combine(this.registryParentFolderPath, RegistryTempName); using (Stream stream = this.fileSystem.OpenFileStream( tempFilePath, FileMode.Create, FileAccess.Write, FileShare.None, callFlushFileBuffers: true)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine(RegistryVersion); foreach (RepoRegistration repo in registry.Values) { writer.WriteLine(repo.ToJson()); } stream.Flush(); } this.fileSystem.MoveAndOverwriteFile(tempFilePath, Path.Combine(this.registryParentFolderPath, RegistryName)); }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:25,代码来源:RepoRegistry.cs
在WriteRegistry()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例5 - WriteExtraSkinningInfo()
using System.IO; //Extra skin data based on https://github.com/Sage-of-Mirrors/SuperBMD/blob/ce1061e9b5f57de112f1d12f6459b938594664a0/SuperBMDLib/source/Model.cs#L193 //Todo this doesn't quite work yet //Need to adjust all mesh name IDs so they are correct private void WriteExtraSkinningInfo(string FileName, Scene outScene, List
Meshes) { StreamWriter test = new StreamWriter(FileName + ".tmp"); StreamReader dae = File.OpenText(FileName); int geomIndex = 0; while (!dae.EndOfStream) { string line = dae.ReadLine(); /* if (line == " ") { AddControllerLibrary(outScene, test); test.WriteLine(line); test.Flush(); } else if (line.Contains(" .Flush(); string[] testLn = line.Split('\"'); string name = testLn[3]; string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">"); test.WriteLine(jointLine); test.Flush(); } else if (line.Contains("")) { foreach (Mesh mesh in outScene.Meshes) { test.WriteLine($" "); test.WriteLine($" "); test.Flush(); } test.WriteLine(line); test.Flush(); }*/ if (line.Contains(""); test.WriteLine(" "); test.WriteLine("#skeleton_root "); test.WriteLine(""); test.WriteLine(" "); test.WriteLine(""); test.WriteLine($" "); test.WriteLine(""); test.WriteLine(" "); test.Flush(); geomIndex++; } else { test.WriteLine(line); test.Flush(); } /* else if (line.Contains(" ", " "); test.WriteLine(matLine); test.Flush(); }*/ } test.Close(); dae.Close(); File.Copy(FileName + ".tmp", FileName, true); File.Delete(FileName + ".tmp"); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:84,代码来源:AssimpSaver.cs
在WriteExtraSkinningInfo()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了8次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例6 - SaveRecentFile()
using System.IO; private void SaveRecentFile(string path) { recentToolStripMenuItem.DropDownItems.Clear(); LoadRecentList(); //load list from file if (!(RecentFiles.Contains(path))) //prevent duplication on recent list RecentFiles.Insert(0, path); //insert given path into list //keep list number not exceeded the given value while (RecentFiles.Count > MRUnumber) { RecentFiles.RemoveAt(MRUnumber); } foreach (string item in RecentFiles) { //create new menu for each item in list STToolStripItem fileRecent = new STToolStripItem(); fileRecent.Click += RecentFile_click; fileRecent.Text = item; fileRecent.Size = new System.Drawing.Size(170, 40); fileRecent.AutoSize = true; fileRecent.Image = null; //add the menu to "recent" menu recentToolStripMenuItem.DropDownItems.Add(fileRecent); } //writing menu list to file //create file called "Recent.txt" located on app folder StreamWriter stringToWrite = new StreamWriter(Runtime.ExecutableDir + "\\Recent.txt"); foreach (string item in RecentFiles) { stringToWrite.WriteLine(item); //write list to stream } stringToWrite.Flush(); //write stream to file stringToWrite.Close(); //close the stream and reclaim memory }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:37,代码来源:MainForm.cs
在SaveRecentFile()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例7 - GetDefaultImports()
using System.IO; // Internal for testing. internal static RazorSourceDocument GetDefaultImports() { using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, Encoding.UTF8)) { writer.WriteLine("@using System"); writer.WriteLine("@using System.Collections.Generic"); writer.WriteLine("@using System.Linq"); writer.WriteLine("@using System.Threading.Tasks"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering"); writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper
Html"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url"); writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor"); writer.Flush(); stream.Position = 0; return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8); } }
开发者ID:aspnet,项目名称:Razor,代码行数:29,代码来源:MvcRazorTemplateEngine.cs
在GetDefaultImports()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Flush的代码示例8 - ToTextAll()
using System.IO; public static string ToTextAll
(IEnumerable records, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null) where TRec : class { if (records == null) return null; if (typeof(DataTable).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return csv.ToString(); } else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec))) { StringBuilder csv = new StringBuilder(); foreach (var dt in records.Take(1)) { configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration; using (var w = new ChoCSVWriter(csv, configuration)) w.Write(dt); } return csv.ToString(); } using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoCSVWriter (writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Write(records); writer.Flush(); stream.Position = 0; return reader.ReadToEnd(); } }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:47,代码来源:ChoCSVWriter.cs
在ToTextAll()方法中,StreamWriter的代码示例类中的Flush的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的StreamWriter.Flush方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。