C# File.OpenText的代码示例

通过代码示例来学习C# File.OpenText方法

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


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

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

File.OpenText的代码示例2 - Read()

    using System.IO;

        public void Read(string fname)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            StreamReader reader = File.OpenText(fname);
            string line;

            string current = "";

            Bones = new STSkeleton();
            Dictionary BoneList = new Dictionary();

            int time = 0;
            while ((line = reader.ReadLine()) != null)
            {
                line = Regex.Replace(line, @"\s+", " ");
                string[] args = line.Replace(";", "").TrimStart().Split(' ');

                if (args[0].Equals("triangles") || args[0].Equals("end") || args[0].Equals("skeleton") || args[0].Equals("nodes"))
                {
                    current = args[0];
                    continue;
                }

                if (current.Equals("nodes"))
                {
                    int id = int.Parse(args[0]);
                    STBone b = new STBone(Bones);
                    b.Text = args[1].Replace('"', ' ').Trim();
                    int s = 2;
                    while (args[s].Contains("\""))
                        b.Text += args[s++];
                    b.parentIndex = int.Parse(args[s]);
                    BoneList.Add(id, b);
                }

                if (current.Equals("skeleton"))
                {
                    if (args[0].Contains("time"))
                        time = int.Parse(args[1]);
                    else
                    {
                        if (time == 0)
                        {
                            STBone b = BoneList[int.Parse(args[0])];
                            b.Position = new Vector3(
                                float.Parse(args[1]),
                                float.Parse(args[2]),
                                float.Parse(args[3]));
                            b.EulerRotation = new Vector3(
                                float.Parse(args[4]),
                                float.Parse(args[5]),
                                float.Parse(args[6]));
                            b.Scale = Vector3.One;

                            b.pos = new Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3]));
                            b.rot = STSkeleton.FromEulerAngles(float.Parse(args[6]), float.Parse(args[5]), float.Parse(args[4]));

                            Bones.bones.Add(b);

                            if (b.parentIndex != -1)
                                b.parentIndex = Bones.bones.IndexOf(BoneList[b.parentIndex]);
                        }
                    }
                }
            }
            Bones.reset();

            Thread.CurrentThread.CurrentCulture = CultureInfo.DefaultThreadCurrentCulture;
        }
    

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

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

File.OpenText的代码示例3 - CountLines()

    using System.IO;

        public static long CountLines(string fileName)
        {
            long count = -1;
            using (StreamReader sr = File.OpenText(fileName))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    count++;
                }
            }
            return count;
        }
    

开发者ID:ohhsodead,项目名称:FileMasta,代码行数:15,代码来源:FileExtensions.cs

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

File.OpenText的代码示例4 - Load()

    using System.IO;

        /// 
        /// Loads a  from the specified file.
        /// 
        /// The file to load a new  from.
        /// The initial value for the returned objects 
        /// The newly loaded .
        public static FileEntryGraph Load(LessIO.Path file, string forFileName)
        {
            var graph = new FileEntryGraph(forFileName);
            using (var f = System.IO.File.OpenText(file.PathString))
            {
                f.ReadLine();//headings
                while (!f.EndOfStream)
                {
                    var line = f.ReadLine().Split(',');
                    if (line.Length != 5)
                        throw new IOException("Expected 5 fields!");
                    /* FIX for github issue #23: 
					 * The problem was that old ExpectedOutput files were all prefixed with C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\ (something like C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\NUnit-2.5.2.9222\SourceDir\PFiles\NUnit 2.5.2\fit-license.txt)
					 * We need to remove Since we don't reasonably know what the original msi filename was, we do know it was the subdirectory of C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\. So we should remove C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\ and the next subdirectory from the path. 
					 * HACK: A better fix would undoubtedly be to cleanup those old file swith code like this and remove this hack from this code forever!
					 */
                    var path = line[0];
                    const string oldRootPath = @"C:\projects\lessmsi\src\Lessmsi.Tests\bin\Debug\";
                    if (path.StartsWith(oldRootPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //this is an old file that would trigger github issue #23, so we'll fix it here...
                        // first remove the old root path: 
                        path = path.Substring(oldRootPath.Length);
                        // now romove the msi filename (which we don't know, but we know it is the next subdirectory of the old root):
                        var lengthOfSubDirectoryName = path.IndexOf('\\', 0);
                        path = path.Substring(lengthOfSubDirectoryName);
                    }
                    graph.Add(new FileEntry(path, Int64.Parse(line[1]), DeserializeDate(line[2]), DeserializeDate(line[3]), DeserializeAttributes(line[4])));
                }
            }
            return graph;
        }
    

开发者ID:activescott,项目名称:lessmsi,代码行数:40,代码来源:FileEntryGraph.cs

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

File.OpenText的代码示例5 - LoadJsonFromFile()

    using System.IO;

        private string LoadJsonFromFile(string fileName)
        {
            lock (this)
            {
                try
                {
                    using (StreamReader file = File.OpenText(ListsDir + fileName))
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        return JToken.ReadFrom(reader).ToString();
                    }
                }
                catch (Exception)
                {
                    File.Create(ListsDir + fileName).Close();
                    return "{}";
                }
            }
        }
    

开发者ID:Andrewthe13th,项目名称:Inventory_Kamera,代码行数:21,代码来源:DatabaseManager.cs

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

File.OpenText的代码示例6 - Payload()

    using System.IO;

        static void Payload()
        {
            string path = "C:/Source/Github/asm-dude.wiki/doc";

            if (!Directory.Exists(path))
            {
                Console.WriteLine("Could not find directory \"" + path + "\".");
                return;
            }

            StringBuilder sb = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            IDictionary> dictionary = new Dictionary>();

            sb2.AppendLine("");

            foreach (string filename in Directory.EnumerateFiles(path, "*.md", SearchOption.TopDirectoryOnly).OrderBy(f => f))
            {
                //Console.WriteLine(filename);
                StreamReader file_Stream = File.OpenText(filename);
                string file_Content = file_Stream.ReadToEnd();
                (string Description, IList Signatures) = Parse(file_Content);
                file_Stream.Close();

                sb.AppendLine(";--------------------------------------------------------");

                ISet mnemonics = new HashSet();
                foreach (Signature s in Signatures)
                {
                    mnemonics.Add(s.mnemonic);
                    foreach (Arch a in s.archs)
                    {
                        if (!dictionary.ContainsKey(a)) dictionary.Add(a, new HashSet());
                        dictionary[a].Add(s.mnemonic);
                    }
                }

                foreach (Mnemonic m in mnemonics)
                {
                    sb2.AppendLine("");

                    #region Handle Signature File
                    sb.AppendLine("GENERAL\t" + m.ToString() + "\t" + Description + "\t" + Path.GetFileNameWithoutExtension(filename));
                    foreach (Signature s in Signatures)
                    {
                        if (s.mnemonic == m)
                        {
                            sb.AppendLine(s.ToString());
                        }
                    }
                    #endregion
                }
                File.WriteAllText(@"C:\Temp\VS\signature-dec2018.txt", sb.ToString());
            }
            sb2.AppendLine("
" + m.ToString() + "" + Description + "" + Get_Arch_Str(Signatures, m) + "
"); File.WriteAllText(@"C:\Temp\VS\overview.txt", sb2.ToString()); foreach (Arch a in dictionary.Keys.OrderBy(f => f)) { Console.WriteLine("#region " + ArchTools.ToString(a)); foreach (Mnemonic m in dictionary[a].OrderBy(f => f)) { Console.WriteLine(" " + m.ToString() + " ; " + Get_Arch_Str(dictionary, m)); } Console.WriteLine("#endregion " + ArchTools.ToString(a)); } }

开发者ID:HJLebbink,项目名称:asm-dude,代码行数:70,代码来源:Program.cs

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

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