C# StreamWriter.Close的代码示例
通过代码示例来学习C# StreamWriter.Close方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
StreamWriter.Close是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamWriter.Close() 已经帮大家高亮显示了,大家可以重点学习StreamWriter.Close() 方法的写法,从而快速掌握该方法的应用。
StreamWriter.Close的代码示例1 - AppendToNewlineSeparatedFile()
using System.IO; public static void AppendToNewlineSeparatedFile(PhysicalFileSystem fileSystem, string filename, string newContent) { using (Stream fileStream = fileSystem.OpenFileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, false)) { using (StreamReader reader = new StreamReader(fileStream)) using (StreamWriter writer = new StreamWriter(fileStream)) { long position = reader.BaseStream.Seek(0, SeekOrigin.End); if (position > 0) { reader.BaseStream.Seek(position - 1, SeekOrigin.Begin); } string lastCharacter = reader.ReadToEnd(); if (lastCharacter != "\n" && lastCharacter != string.Empty) { writer.Write("\n"); } writer.Write(newContent.Trim()); writer.Write("\n"); } fileStream.Close(); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:28,代码来源:BlobPrefetcher.cs
在AppendToNewlineSeparatedFile()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例2 - RunCommandWithWaitAndStdIn()
using System.IO; ///
/// Run the specified command as an external program. This method will return once the GVFSLock has been acquired. /// /// The ID of the process that acquired the lock. ///private static ManualResetEventSlim RunCommandWithWaitAndStdIn( GVFSFunctionalTestEnlistment enlistment, int resetTimeout, string pathToCommand, string args, string lockingProcessCommandName, string stdinToQuit, out int processId) { ManualResetEventSlim resetEvent = new ManualResetEventSlim(initialState: false); ProcessStartInfo processInfo = new ProcessStartInfo(pathToCommand); processInfo.WorkingDirectory = enlistment.RepoRoot; processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardInput = true; processInfo.Arguments = args; Process holdingProcess = Process.Start(processInfo); StreamWriter stdin = holdingProcess.StandardInput; processId = holdingProcess.Id; enlistment.WaitForLock(lockingProcessCommandName); Task.Run( () => { resetEvent.Wait(resetTimeout); try { // Make sure to let the holding process end. if (stdin != null) { stdin.WriteLine(stdinToQuit); stdin.Close(); } if (holdingProcess != null) { bool holdingProcessHasExited = holdingProcess.WaitForExit(10000); if (!holdingProcess.HasExited) { holdingProcess.Kill(); } holdingProcess.Dispose(); holdingProcessHasExited.ShouldBeTrue("Locking process did not exit in time."); } } catch (Exception ex) { Assert.Fail($"{nameof(RunCommandWithWaitAndStdIn)} exception closing stdin {ex.ToString()}"); } finally { resetEvent.Set(); } }); return resetEvent; } that can be signaled to exit the lock acquisition program.
开发者ID:microsoft,项目名称:VFSForGit,代码行数:72,代码来源:GitHelpers.cs
在RunCommandWithWaitAndStdIn()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例3 - InvokeGitImpl()
using System.IO; protected virtual Result InvokeGitImpl( string command, string workingDirectory, string dotGitDirectory, bool useReadObjectHook, Action
writeStdIn, Action parseStdOutLine, int timeoutMs, string gitObjectsDirectory = null) { if (failedToSetEncoding && writeStdIn != null) { return new Result(string.Empty, "Attempting to use to stdin, but the process does not have the right input encodings set.", Result.GenericFailureCode); } try { // From https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx // To avoid deadlocks, use asynchronous read operations on at least one of the streams. // Do not perform a synchronous read to the end of both redirected streams. using (this.executingProcess = this.GetGitProcess(command, workingDirectory, dotGitDirectory, useReadObjectHook, redirectStandardError: true, gitObjectsDirectory: gitObjectsDirectory)) { StringBuilder output = new StringBuilder(); StringBuilder errors = new StringBuilder(); this.executingProcess.ErrorDataReceived += (sender, args) => { if (args.Data != null) { errors.Append(args.Data + "\n"); } }; this.executingProcess.OutputDataReceived += (sender, args) => { if (args.Data != null) { if (parseStdOutLine != null) { parseStdOutLine(args.Data); } else { output.Append(args.Data + "\n"); } } }; lock (this.executionLock) { lock (this.processLock) { if (this.stopping) { return new Result(string.Empty, nameof(GitProcess) + " is stopping", Result.GenericFailureCode); } this.executingProcess.Start(); if (this.LowerPriority) { try { this.executingProcess.PriorityClass = ProcessPriorityClass.BelowNormal; } catch (InvalidOperationException) { // This is thrown if the process completes before we can set its priority. } } } writeStdIn?.Invoke(this.executingProcess.StandardInput); this.executingProcess.StandardInput.Close(); this.executingProcess.BeginOutputReadLine(); this.executingProcess.BeginErrorReadLine(); if (!this.executingProcess.WaitForExit(timeoutMs)) { this.executingProcess.Kill(); return new Result(output.ToString(), "Operation timed out: " + errors.ToString(), Result.GenericFailureCode); } } return new Result(output.ToString(), errors.ToString(), this.executingProcess.ExitCode); } } catch (Win32Exception e) { return new Result(string.Empty, e.Message, Result.GenericFailureCode); } finally { this.executingProcess = null; } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:99,代码来源:GitProcess.cs
在InvokeGitImpl()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例4 - 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(" ", $" 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的代码示例类中的Close的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例5 - Save()
using System.IO; public void Save(System.IO.Stream stream) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(stream)) { foreach (STGenericObject obj in objects) { file.WriteLine($"Obj Name:" + obj.ObjectName); file.WriteLine($"Bone_Suport"); file.WriteLine($"UV_Num:1"); file.WriteLine($"vert_Array"); foreach (Vertex v in obj.vertices) { file.WriteLine($"{v.pos.X},{v.pos.Y},{v.pos.Z}"); file.WriteLine($"{v.nrm.X},{v.nrm.Y},{v.nrm.Z}"); file.WriteLine($"{v.col.X * 255},{v.col.Y * 255},{v.col.Z * 255},{v.col.W * 255}"); file.WriteLine($"{v.uv0.X},{v.uv0.Y}"); // file.WriteLine($"{v.uv1.X},{v.uv1.Y}"); } file.WriteLine($"face_Array"); for (int f = 0; f < obj.faces.Count / 3; f++) { file.WriteLine($"{obj.faces[f] + 1},{obj.faces[f++] + 1},{obj.faces[f++] + 1}"); } file.WriteLine($"bone_Array"); foreach (Vertex v in obj.vertices) { if (v.boneNames.Count == 1) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]}"); if (v.boneNames.Count == 2) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]}"); if (v.boneNames.Count == 3) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]}"); if (v.boneNames.Count == 4) file.WriteLine($"{v.boneNames[0]} {v.boneWeights[0]} {v.boneNames[1]} {v.boneWeights[1]} {v.boneNames[2]} {v.boneWeights[2]} {v.boneNames[3]} {v.boneWeights[3]}"); } } file.Close(); } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:41,代码来源:CsvModels.cs
在Save()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例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的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例7 - Save()
using System.IO; public static void Save(STSkeletonAnimation anim, String Fname) { System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; STSkeleton Skeleton = anim.GetActiveSkeleton(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Fname)) { file.WriteLine("version 1"); file.WriteLine("nodes"); foreach (STBone b in Skeleton.bones) { file.WriteLine(Skeleton.bones.IndexOf(b) + " \"" + b.Text + "\" " + b.parentIndex); } file.WriteLine("end"); file.WriteLine("skeleton"); anim.SetFrame(0); for (int i = 0; i <= Math.Max(1, anim.FrameCount); i++) { anim.SetFrame(i); anim.NextFrame(); file.WriteLine($"time {i}"); foreach (var sb in anim.AnimGroups) { STBone b = Skeleton.GetBone(sb.Name); if (b == null) continue; Vector3 eul = STMath.ToEulerAngles(b.rot); Vector3 scale = b.GetScale(); Vector3 translate = b.GetPosition(); file.WriteLine($"{ Skeleton.bones.IndexOf(b)} {translate.X} {translate.Y} {translate.Z} {eul.X} {eul.Y} {eul.Z}"); } } file.WriteLine("end"); file.Close(); } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:45,代码来源:SMD.cs
在Save()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
StreamWriter.Close的代码示例8 - SaveQFontDataToFile()
using System.IO; public static void SaveQFontDataToFile(QFontData data, string filePath) { var lines = data.Serialize(); StreamWriter writer = new StreamWriter(filePath + ".qfont"); foreach (var line in lines) writer.WriteLine(line); writer.Close(); }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:16,代码来源:Builder.cs
在SaveQFontDataToFile()方法中,StreamWriter的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的StreamWriter.Close方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。