C# File.WriteAllLines的代码示例
通过代码示例来学习C# File.WriteAllLines方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
File.WriteAllLines是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.WriteAllLines() 已经帮大家高亮显示了,大家可以重点学习File.WriteAllLines() 方法的写法,从而快速掌握该方法的应用。
File.WriteAllLines的代码示例1 - LogDirectoryEnumeration()
using System.IO; private void LogDirectoryEnumeration(string sourceRoot, string targetRoot, string folderName, string logfile) { try { if (!Directory.Exists(targetRoot)) { Directory.CreateDirectory(targetRoot); } string folder = Path.Combine(sourceRoot, folderName); string targetLog = Path.Combine(targetRoot, logfile); List
lines = new List (); if (Directory.Exists(folder)) { DirectoryInfo packDirectory = new DirectoryInfo(folder); lines.Add($"Contents of {folder}:"); foreach (FileInfo file in packDirectory.EnumerateFiles()) { lines.Add($"{file.Name, -70} {file.Length, 16}"); } } File.WriteAllLines(targetLog, lines.ToArray()); } catch (Exception e) { this.WriteMessage(string.Format( "Failed to log file sizes for {0} in {1} with exception {2}. logfile: {3}", folderName, sourceRoot, e, logfile)); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:39,代码来源:DiagnoseVerb.cs
在LogDirectoryEnumeration()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例2 - PrefetchFilesFromFileListFile()
using System.IO; [TestCase, Order(12)] public void PrefetchFilesFromFileListFile() { string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file"); try { File.WriteAllLines( tempFilePath, new[] { Path.Combine("GVFS", "GVFS", "Program.cs"), Path.Combine("GVFS", "GVFS.FunctionalTests", "GVFS.FunctionalTests.csproj") }); this.ExpectBlobCount(this.Enlistment.Prefetch($"--files-list \"{tempFilePath}\""), 2); } finally { File.Delete(tempFilePath); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:23,代码来源:PrefetchVerbTests.cs
在PrefetchFilesFromFileListFile()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例3 - Fix_Issue_1171()
[Fact] [Description("Issue #1171")] public void Fix_Issue_1171() { var tempFile = System.IO.Path.GetTempFileName(); try { System.IO.File.WriteAllLines(tempFile, new[] { "Windows Registry Editor Version 5.00", "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Test]", "\"New Value #1\"=dword:00000001", "\"New Value #2\"=hex(b):02,00,00,00,00,00,00,00", }); var values = WixSharp.RegFileImporter.ImportFrom(tempFile); } finally { tempFile.DeleteIfExists(); } }
开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:22,代码来源:IssueFixesTest.cs
在Fix_Issue_1171()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例4 - Form1_DragDrop()
using System.IO; private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] D = e.Data.GetData(DataFormats.FileDrop) as string[]; foreach (var s in D) { if (File.Exists(s)) { GerberLibrary.Eagle.EagleLoader EL = new GerberLibrary.Eagle.EagleLoader(s); string name = Path.GetFileNameWithoutExtension(s); string folder = Path.GetDirectoryName(s); List
alllines = new List (); Dictionary > placements = new Dictionary >(); foreach(var a in EL.DevicePlacements) { string N = "part_"+a.library + "_" + a.package + "_" + a.value; N = N.Replace("-", "_"); N = N.Replace(".", "_"); N = N.Replace(" ", "_"); if (placements.ContainsKey(N) == false) { placements[N] = new List (); } placements[N].Add(new Place(a.x, a.y, a.rot.Degrees, a.name)); } alllines.Add("#pragma once"); alllines.Add(""); alllines.Add("typedef struct Placement {"); alllines.Add("\tdouble x,y,rot;"); alllines.Add("\tconst char* name;"); alllines.Add("} Placement;"); alllines.Add(""); foreach (var a in placements) { string thename = a.Key; string count = a.Value.Count().ToString(); alllines.Add(string.Format("#define __{0}_count {1}", thename, count)); alllines.Add(string.Format("const Placement {0}[{1}] = ",thename, count)+"{"); foreach (var b in a.Value) { alllines.Add("\t{" + string.Format("\t{0}, {1}, {2}, \"{3}\"", fd(b.x), fd(b.y), fd(b.rot), b.name) + "},"); } alllines.Add("};"); alllines.Add(""); } alllines.Add(""); File.WriteAllLines(Path.Combine(folder, name + "_components.h"), alllines); } } } }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:69,代码来源:Form1.cs
在Form1_DragDrop()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例5 - RotateFile()
using System.IO; private static void RotateFile(ProgressLog log, string filename, string outfile, string[] args) { double dx = 0; double dy = 0; double cx = 0; double cy = 0; double angle = 0; if (args.Count() > 2) double.TryParse(args[2], out dx); if (args.Count() > 3) double.TryParse(args[3], out dy); if (args.Count() > 4) double.TryParse(args[4], out cx); if (args.Count() > 5) double.TryParse(args[5], out cy); if (args.Count() > 6) double.TryParse(args[6], out angle); var T = Gerber.FindFileType(filename); if (T == BoardFileType.Drill) { ExcellonFile EF = new ExcellonFile(); EF.Load(log, filename); EF.Write(outfile, dx, dy, cx, cy, angle); } else { BoardSide Side; BoardLayer Layer; Gerber.DetermineBoardSideAndLayer(args[0], out Side, out Layer); GerberTransposer.Transform(log, filename, outfile, dx, dy, cx, cy, angle); var lines = PolyLineSet.SanitizeInputLines(System.IO.File.ReadAllLines(args[0]).ToList()); System.IO.File.WriteAllLines(args[0] + "sanit.txt", lines); Gerber.SaveGerberFileToImage(log, outfile, outfile + "_render.png", 200, Color.Black, Color.White); } }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:37,代码来源:GerberMover.cs
在RotateFile()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例6 - Main()
using System.IO; static void Main(string[] args) { CultureInfo ci = new CultureInfo("nl-NL"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; if (args.Length == 0) { Console.WriteLine("Usage: KicadPartsToCSV
[part name] [part name] - omit part names to see list of parts"); return; } string inputfile = args[0]; if (File.Exists(inputfile)) { BOM.LoadRotationOffsets(); string Name = Path.GetFileNameWithoutExtension(inputfile); string kicadschname = Path.Combine(Path.GetDirectoryName(inputfile), Name + ".kicad_sch"); string kicadpcbname = Path.Combine(Path.GetDirectoryName(inputfile), Name + ".kicad_pcb"); if (File.Exists(kicadschname) && File.Exists(kicadpcbname)) { // try { BOM TheBOM = new BOM(); TheBOM.LoadKicad(kicadschname, kicadpcbname, new StandardConsoleLog()); if (args.Length == 1) { string csvoutputname = Path.Combine(Path.GetDirectoryName(inputfile), Name + ".part_types.csv"); List OutputFile2 = new List (); foreach (var a in TheBOM.DeviceTree.Keys) { OutputFile2.Add(a); } File.WriteAllLines(csvoutputname, OutputFile2); } else { string csvoutputname = Path.Combine(Path.GetDirectoryName(inputfile), Name + ".part_locations.csv"); List OutputFile2 = new List (); OutputFile2.Add(String.Format("type;x;y")); for(int j = 1;j .WriteAllLines(csvoutputname, OutputFile2); } } } } }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:66,代码来源:Program.cs
在Main()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例7 - Write()
public static void Write(string filename, int w, int h, List
Polygons, double strokewidth) { List OutLines = new List (); OutLines.Add(""); OutLines.Add(String.Format(""); System.IO.File.WriteAllLines(filename, OutLines); }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:47,代码来源:SVGWriter.cs
在Write()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
File.WriteAllLines的代码示例8 - AssertCSharpDocumentMatchesBaseline()
using System.IO; protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument cSharpDocument) { if (FileName == null) { var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(FileName)} is null)."; throw new InvalidOperationException(message); } var baselineFileName = Path.ChangeExtension(FileName, ".codegen.cs"); var baselineDiagnosticsFileName = Path.ChangeExtension(FileName, ".diagnostics.txt"); if (GenerateBaselines) { var baselineFullPath = Path.Combine(TestProjectRoot, baselineFileName); File.WriteAllText(baselineFullPath, cSharpDocument.GeneratedCode); var baselineDiagnosticsFullPath = Path.Combine(TestProjectRoot, baselineDiagnosticsFileName); var lines = cSharpDocument.Diagnostics.Select(RazorDiagnosticSerializer.Serialize).ToArray(); if (lines.Any()) { File.WriteAllLines(baselineDiagnosticsFullPath, lines); } else if (File.Exists(baselineDiagnosticsFullPath)) { File.Delete(baselineDiagnosticsFullPath); } return; } var codegenFile = TestFile.Create(baselineFileName, GetType().GetTypeInfo().Assembly); if (!codegenFile.Exists()) { throw new XunitException($"The resource {baselineFileName} was not found."); } var baseline = codegenFile.ReadAllText(); // Normalize newlines to match those in the baseline. var actual = cSharpDocument.GeneratedCode.Replace("\r", "").Replace("\n", "\r\n"); Assert.Equal(baseline, actual); var baselineDiagnostics = string.Empty; var diagnosticsFile = TestFile.Create(baselineDiagnosticsFileName, GetType().GetTypeInfo().Assembly); if (diagnosticsFile.Exists()) { baselineDiagnostics = diagnosticsFile.ReadAllText(); } var actualDiagnostics = string.Concat(cSharpDocument.Diagnostics.Select(d => RazorDiagnosticSerializer.Serialize(d) + "\r\n")); Assert.Equal(baselineDiagnostics, actualDiagnostics); }
开发者ID:aspnet,项目名称:Razor,代码行数:54,代码来源:IntegrationTestBase.cs
在AssertCSharpDocumentMatchesBaseline()方法中,File的代码示例类中的WriteAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的File.WriteAllLines方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。