C# StreamReader.Close的代码示例

通过代码示例来学习C# StreamReader.Close方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


StreamReader.Close是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamReader.Close() 已经帮大家高亮显示了,大家可以重点学习StreamReader.Close() 方法的写法,从而快速掌握该方法的应用。

StreamReader.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()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例2 - 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.WriteLine("        #skeleton_root");
                         test.WriteLine("        ");
                         test.WriteLine("         ");
                         test.WriteLine($"          ");
                         test.WriteLine("         ");
                         test.WriteLine("        ");
                         test.WriteLine("       ");

                         test.WriteLine("      ");
                         test.Flush();
                     }

                     test.WriteLine(line);
                     test.Flush();
                 }*/
                if (line.Contains(" ");
                    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()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例3 - LoadRecentList()

    using System.IO;
        private void LoadRecentList()
        {//try to load file. If file isn't found, do nothing
            RecentFiles.Clear();

            if (File.Exists(Runtime.ExecutableDir + "\\Recent.txt"))
            {
                StreamReader listToRead = new StreamReader(Runtime.ExecutableDir + "\\Recent.txt"); //read file stream
                string line;
                while ((line = listToRead.ReadLine()) != null) //read each line until end of file
                {
                    if (File.Exists(line))
                        RecentFiles.Add(line); //insert to list
                }
                listToRead.Close(); //close the stream
            }
            foreach (string item in RecentFiles)
            {
                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;
                recentToolStripMenuItem.DropDownItems.Add(fileRecent); //add the menu to "recent" menu
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:27,代码来源:MainForm.cs

在LoadRecentList()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例4 - ReadFileFromResource()

    using System.IO;

        #endregion Public properties

        #region Public methods

        public string ReadFileFromResource(string fileName)
        {
            Stream _stream = ReadFileFromResourceToStream(fileName);
            string _result;
            StreamReader sr = new StreamReader(_stream);
            try
            {
                _result = sr.ReadToEnd();
            }
            finally
            {
                sr.Close();
            }
            return _result;
        }
    

开发者ID:ClosedXML,项目名称:ClosedXML,代码行数:21,代码来源:ResourceFileExtractor.cs

在ReadFileFromResource()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例5 - ToTextAll()

    using System.IO;


        public static string ToTextAll(IEnumerable records, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null)
        {
            if (records == null) return null;

            if (typeof(DataTable).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoJSONWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }
            else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoJSONWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }


            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoJSONWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                parser.Configuration.JSONPath = jsonPath;

                parser.Write(records);
                parser.Close();
                writer.Flush();
                
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:53,代码来源:ChoJSONWriter.cs

在ToTextAll()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例6 - ToText()

    using System.IO;

        public static string ToText(TRec record, ChoXmlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string xpath = null)
            where TRec : class
        {
            if (record is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as DataTable);
                return xml.ToString();
            }
            else if (record is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as IDataReader);
                return xml.ToString();
            }

            if (configuration == null)
            {
                configuration = new ChoXmlRecordConfiguration(typeof(TRec));
                configuration.IgnoreRootName = true;
                configuration.RootName = null;
                configuration.IgnoreNodeName = false;
            }

            if (record != null)
            {
                if (configuration.NodeName.IsNullOrWhiteSpace())
                {
                    ChoDynamicObject rec1 = record as ChoDynamicObject;
                    if (rec1 != null)
                    {
                        if (rec1.DynamicObjectName != ChoDynamicObject.DefaultName)
                        {
                            configuration.NodeName = rec1.DynamicObjectName;
                        }
                        else
                        {
                            //configuration.IgnoreNodeName = true;
                            //configuration.NodeName = null;
                        }
                    }
                    else
                    {
                        XmlRootAttribute root = ChoType.GetCustomAttribute(record.GetType(), false);
                        string nodeName = "XElement";
                        if (root != null && !root.ElementName.IsNullOrWhiteSpace())
                            nodeName = root.ElementName.Trim();
                        else
                            nodeName = record.GetType().Name;

                        configuration.NodeName = nodeName;
                    }
                }
            }

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoXmlWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                //parser.Configuration.XPath = xpath;

                if (record != null)
                    parser.Write(ChoEnumerable.AsEnumerable(record));

                parser.Close();

                writer.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:77,代码来源:ChoXmlWriter.cs

在ToText()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例7 - ToTextAll()

    using System.IO;


        public static string ToTextAll(IEnumerable records, ChoYamlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string yamlPath = null)
        {
            if (records == null) return null;

            if (typeof(DataTable).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoYamlWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }
            else if (typeof(IDataReader).IsAssignableFrom(typeof(TRec)))
            {
                StringBuilder json = new StringBuilder();

                foreach (var dt in records.Take(1))
                {
                    using (var w = new ChoYamlWriter(json, configuration))
                    {
                        w.Write(dt);
                    }
                }

                return json.ToString();
            }


            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoYamlWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                parser.Configuration.YamlPath = yamlPath;

                parser.Write(records);
                parser.Close();
                writer.Flush();
                
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:53,代码来源:ChoYamlWriter.cs

在ToTextAll()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.Close的代码示例8 - testUriToFileStream()

    using System.IO;

        [Test]
        public void testUriToFileStream()
        {
            DirectoryInfo dInfo = Directory.CreateDirectory(RolloverHandlerTest.TEST_DIR_NAME);
            string fullName = CreateFile(dInfo, "test.log");

            LocalFileSystem fs = new LocalFileSystem();
            ILogFileInfo info = fs.GetLogfileInfo(fullName);
            Assert.True(info.Length > 0);
            Assert.True(info.OriginalLength == info.Length);
            Stream stream = info.OpenStream();
            Assert.True(stream.CanSeek);
            StreamReader reader = new StreamReader(stream);
            string line = reader.ReadLine();
            Assert.True(line.StartsWith("line number", StringComparison.InvariantCultureIgnoreCase));
            reader.Close();
        }
    

开发者ID:zarunbal,项目名称:LogExpert,代码行数:19,代码来源:LocalFileSystemTest.cs

在testUriToFileStream()方法中,StreamReader的代码示例类中的Close的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的StreamReader.Close方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。