C# FileStream.ToString的代码示例
通过代码示例来学习C# FileStream.ToString方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
FileStream.ToString是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的FileStream.ToString() 已经帮大家高亮显示了,大家可以重点学习FileStream.ToString() 方法的写法,从而快速掌握该方法的应用。
FileStream.ToString的代码示例1 - WriteAllEntries()
using System.IO; private void WriteAllEntries(uint version, bool isFinal) { try { using (Stream indexStream = new FileStream(this.indexLockPath, FileMode.Create, FileAccess.Write, FileShare.None)) using (BinaryWriter writer = new BinaryWriter(indexStream)) { writer.Write(IndexHeader); writer.Write(EndianHelper.Swap(version)); writer.Write((uint)0); // Number of entries placeholder uint lastStringLength = 0; LsTreeEntry entry; while (this.entryQueue.TryTake(out entry, Timeout.Infinite)) { this.WriteEntry(writer, version, entry.Sha, entry.Filename, ref lastStringLength); } // Update entry count writer.BaseStream.Position = EntryCountOffset; writer.Write(EndianHelper.Swap(this.entryCount)); writer.Flush(); } this.AppendIndexSha(); if (isFinal) { this.ReplaceExistingIndex(); } } catch (Exception e) { this.tracer.RelatedError("Failed to generate index: {0}", e.ToString()); this.HasFailures = true; } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:38,代码来源:GitIndexGenerator.cs
在WriteAllEntries()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例2 - OutputFileContents()
using System.IO; public static void OutputFileContents(string filename, Action
contentsValidator = null) { try { using (StreamReader reader = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { Console.WriteLine("----- {0} -----", filename); string contents = reader.ReadToEnd(); if (contentsValidator != null) { contentsValidator(contents); } Console.WriteLine(contents + "\n\n"); } } catch (IOException ex) { Console.WriteLine("Unable to read logfile at {0}: {1}", filename, ex.ToString()); } }
开发者ID:microsoft,项目名称:VFSForGit,代码行数:25,代码来源:TestResultsHelper.cs
在OutputFileContents()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例3 - SaveFileForCompression()
using System.IO; private void SaveFileForCompression(bool Compress, string[] fileNames, ICompressionFormat compressionFormat) { if (fileNames.Length == 0) return; string ext = Compress ? ".comp" : ""; if (compressionFormat.Extension.Length > 0 && Compress) ext = compressionFormat.Extension[0].Replace("*", string.Empty); List
failedFiles = new List (); if (fileNames.Length > 1) { FolderSelectDialog ofd = new FolderSelectDialog(); if (ofd.ShowDialog() == DialogResult.OK) { foreach (var file in fileNames) { string name = Path.GetFileName(file); name = name.Count(c => c == '.') > 1 && !Compress ? name.Remove(name.LastIndexOf('.')) : name; using (var data = new FileStream(file, FileMode.Open, FileAccess.Read)) { try { Stream stream; if (Compress) stream = compressionFormat.Compress(data); else { compressionFormat.Identify(data, file); stream = compressionFormat.Decompress(data); } if (stream != null) { stream.ExportToFile($"{ofd.SelectedPath}/{name}{ext}"); stream.Flush(); stream.Close(); } } catch (Exception ex) { failedFiles.Add($"{file} \n\n {ex} \n\n"); } } } if (failedFiles.Count > 0) { string action = Compress ? "compress" : "decompress"; STErrorDialog.Show($"Some files failed to {action}! See detail list of failed files.", "Switch Toolbox", string.Join("\n", failedFiles.ToArray())); } else MessageBox.Show("Files batched successfully!"); } } else { SaveFileDialog sfd = new SaveFileDialog(); string name = Path.GetFileName(fileNames[0]); sfd.FileName = name + ext; sfd.Filter = "All files(*.*)|*.*"; Cursor.Current = Cursors.Default; if (sfd.ShowDialog() == DialogResult.OK) { try { using (var data = new FileStream(fileNames[0], FileMode.Open, FileAccess.Read)) { Stream stream; if (Compress) stream = compressionFormat.Compress(data); else { compressionFormat.Identify(data, fileNames[0]); stream = compressionFormat.Decompress(data); } if (stream != null) { stream.ExportToFile(sfd.FileName); stream.Flush(); stream.Close(); MessageBox.Show($"File has been saved to {sfd.FileName}", "Save Notification"); } } } catch (Exception ex) { string action = Compress ? "compress" : "decompress"; STErrorDialog.Show($"Failed to {action}! See details for info.", "Switch Toolbox", ex.ToString()); } } } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:99,代码来源:CompressionMenus.cs
在SaveFileForCompression()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例4 - WritePidFile_WorksAsExpected()
using System.IO; [Fact] public void WritePidFile_WorksAsExpected() { // Arrange var expectedProcessId = Process.GetCurrentProcess().Id; var expectedRzcPath = typeof(ServerCommand).Assembly.Location; var expectedFileName = $"rzc-{expectedProcessId}"; var directoryPath = Path.Combine(Path.GetTempPath(), "RazorTest", Guid.NewGuid().ToString()); var path = Path.Combine(directoryPath, expectedFileName); var pipeName = Guid.NewGuid().ToString(); var server = GetServerCommand(pipeName); // Act & Assert try { using (var _ = server.WritePidFile(directoryPath)) { Assert.True(File.Exists(path)); // Make sure another stream can be opened while the write stream is still open. using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Write | FileShare.Delete)) using (var reader = new StreamReader(fileStream, Encoding.UTF8)) { var lines = reader.ReadToEnd().Split(Environment.NewLine); Assert.Equal(new[] { expectedProcessId.ToString(), "rzc", expectedRzcPath, pipeName }, lines); } } // Make sure the file is deleted on dispose. Assert.False(File.Exists(path)); } finally { // Cleanup after the test. if (Directory.Exists(directoryPath)) { Directory.Delete(directoryPath, recursive: true); } } }
开发者ID:aspnet,项目名称:Razor,代码行数:42,代码来源:ServerCommandTest.cs
在WritePidFile_WorksAsExpected()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例5 - LargeXmlToCSV()
using System.IO; [Test] public static void LargeXmlToCSV() { return; ChoETLFrxBootstrap.TraceLevel = System.Diagnostics.TraceLevel.Off; XmlReaderSettings settings = new XmlReaderSettings(); // SET THE RESOLVER settings.XmlResolver = new XmlUrlResolver(); settings.ValidationType = ValidationType.DTD; settings.DtdProcessing = DtdProcessing.Parse; settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); settings.IgnoreWhitespace = true; Console.WriteLine(DateTime.Now.ToString()); using (var r = new ChoXmlReader(XmlReader.Create(@"dblp.xml", settings))) { using (FileStream fs = File.Open(@"dblp.csv", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) using (BufferedStream bs = new BufferedStream(fs)) using (var w = new ChoCSVWriter(bs) .WithFirstLineHeader()) { w.NotifyAfter(1000); w.Write(r); } } Console.WriteLine(DateTime.Now.ToString()); }
开发者ID:Cinchoo,项目名称:ChoETL,代码行数:33,代码来源:Program.cs
在LargeXmlToCSV()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例6 - Save()
using System.IO; ///
/// Save tbl file /// public void Save() { var myFile = new FileStream(_fileName, FileMode.Create, FileAccess.Write); var tblFile = new StreamWriter(myFile, Encoding.Unicode); //ASCII if (tblFile.BaseStream.CanWrite) { //Save tbl set foreach (var dte in _dteList) if (dte.Value.Type != DteType.EndBlock && dte.Value.Type != DteType.EndLine) tblFile.WriteLine(dte.Value.Entry + "=" + dte.Value); else tblFile.WriteLine(dte.Value.Entry); //Save bookmark tblFile.WriteLine(); foreach (var mark in BookMarks) tblFile.WriteLine(mark.ToString()); //Add to line at end of file. Needed for some apps that using tbl file tblFile.WriteLine(); tblFile.WriteLine(); } //close file tblFile.Close(); }
开发者ID:abbaye,项目名称:WpfHexEditorControl,代码行数:33,代码来源:TBLStream.cs
在Save()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例7 - Append()
using System.IO; protected override bool Append(string filePath, IEnumerable
historyItems) { if (!string.IsNullOrEmpty(filePath)) { lock (thisLock) { FileHelpers.CreateDirectoryFromFilePath(filePath); using (FileStream fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read, 4096, FileOptions.WriteThrough)) using (XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.Indentation = 4; foreach (HistoryItem historyItem in historyItems) { writer.WriteStartElement("HistoryItem"); writer.WriteElementIfNotEmpty("Filename", historyItem.FileName); writer.WriteElementIfNotEmpty("Filepath", historyItem.FilePath); writer.WriteElementIfNotEmpty("DateTimeUtc", historyItem.DateTime.ToString("o")); writer.WriteElementIfNotEmpty("Type", historyItem.Type); writer.WriteElementIfNotEmpty("Host", historyItem.Host); writer.WriteElementIfNotEmpty("URL", historyItem.URL); writer.WriteElementIfNotEmpty("ThumbnailURL", historyItem.ThumbnailURL); writer.WriteElementIfNotEmpty("DeletionURL", historyItem.DeletionURL); writer.WriteElementIfNotEmpty("ShortenedURL", historyItem.ShortenedURL); writer.WriteEndElement(); } writer.WriteWhitespace(Environment.NewLine); } Backup(FilePath); } return true; } return false; }
开发者ID:ShareX,项目名称:ShareX,代码行数:42,代码来源:HistoryManagerXML.cs
在Append()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
FileStream.ToString的代码示例8 - Button2Click()
using System.IO; private void Button2Click(object sender, EventArgs e) { try { using var stream = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var sw = new Stopwatch(); sw.Start(); using IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream); var openTiming = sw.ElapsedMilliseconds; // reader.IsFirstRowAsColumnNames = firstRowNamesCheckBox.Checked; ds = reader.AsDataSet(new ExcelDataSetConfiguration() { UseColumnDataType = false, ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration() { UseHeaderRow = firstRowNamesCheckBox.Checked } }); toolStripStatusLabel1.Text = "Elapsed: " + sw.ElapsedMilliseconds.ToString() + " ms (" + openTiming.ToString() + " ms to open)"; var tablenames = GetTablenames(ds.Tables); sheetCombo.DataSource = tablenames; if (tablenames.Count > 0) sheetCombo.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
开发者ID:ExcelDataReader,项目名称:ExcelDataReader,代码行数:37,代码来源:Form1.cs
在Button2Click()方法中,FileStream的代码示例类中的ToString的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的FileStream.ToString方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。