当前位置: 首页>>代码示例>>C#>>正文


C# StreamWriter.WriteLine方法代码示例

本文整理汇总了C#中StreamWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.WriteLine方法的具体用法?C# StreamWriter.WriteLine怎么用?C# StreamWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StreamWriter的用法示例。


在下文中一共展示了StreamWriter.WriteLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Go

    public void Go()
    {
        // analyze gives you information on a type; useful during development
         //Analyze( typeof( IAICallback ) );
         // Analyze( typeof( IUnitDef ) );
         //Analyze( typeof( IMoveData ) );

        csfile = new StreamWriter( "ABICInterface_generated.cs", false );

        WriteHeaderComments( csfile );
        csfile.WriteLine( "using System;" );
        csfile.WriteLine( "using System.Runtime.CompilerServices;" );
        csfile.WriteLine( "using System.Runtime.InteropServices;" );
        csfile.WriteLine( "using System.Text;" );
        csfile.WriteLine( "using System.IO;" );
        csfile.WriteLine( "" );
        csfile.WriteLine( "namespace CSharpAI" );
        csfile.WriteLine( "{");
        csfile.WriteLine( "    public class ABICInterface" );
        csfile.WriteLine( "    {" );

        StreamReader sr = new StreamReader( "ABICInterface_manualtweaks.txt" );
        csfile.Write( sr.ReadToEnd() );
        sr.Close();

        // Parameters: typename in CSAIInterfaces, native Spring typename, methods to ignore
        GenerateFor( typeof( IAICallback ), "IAICallback", new string[]{"UnitIsBusy"} );
        GenerateFor( typeof( IUnitDef ), "UnitDef", new string[]{} );
        GenerateFor( typeof( IMoveData ), "MoveData", new string[]{} );
        GenerateFor( typeof( IFeatureDef ), "FeatureDef", new string[]{} );

        csfile.WriteLine( "    }" );
        csfile.WriteLine( "}");
        csfile.Close();
    }
开发者ID:achoum,项目名称:spring,代码行数:35,代码来源:MonoABICInterfaceGenerator.cs

示例2: Main

    static void Main()
    {
        var text = new StreamReader(@"..\..\Files\text.txt");
        var text2 = new StreamReader(@"..\..\Files\text2.txt");
        var write = new StreamWriter(@"..\..\Files\concetenate.txt");
        string curentLine = "";
        using (write)
        {
            using (text)
            {
                curentLine = text.ReadLine();
                while (curentLine != null)
                {
                    write.WriteLine(text.ReadLine());
                    curentLine = text.ReadLine();
                }
            }

            write.WriteLine();
            using (text2)
            {
                curentLine = text2.ReadLine();
                while (curentLine != null)
                {
                    write.WriteLine(text2.ReadLine());
                    curentLine = text2.ReadLine();
                }
            }

        }
        Console.WriteLine("Complete Work!!!");

        Console.ReadLine();
    }
开发者ID:pepm99,项目名称:ProjectWorker,代码行数:34,代码来源:ConcatenateTextFiles.cs

示例3: OnGUI

 void OnGUI()
 {
     GUIStyle mgui = new GUIStyle();
     mgui.fontSize = 200;
     if (mode == "main")
         GUI.DrawTexture (getRect(0.1, 0.1, 0.3, 0.1), target);
     else
         GUI.DrawTexture (getRect(0.6, 0.1, 0.3, 0.1), target);
     if (GUI.Button(getRect(0.1, 0.1, 0.3, 0.1), "메인 맵"))
         mode = "main";
     if (GUI.Button(getRect(0.6, 0.1, 0.3, 0.1), "커스텀 맵"))
         mode = "costom";
     for(int y=0;y<2;y++)
     {
         for (int x = 0; x < 5; x++)
         {
             if (GUI.Button(getRect(0.05+0.2*x, 0.3+0.2*y, 0.1, 0.1), (5 * y + x + 1).ToString()))
             {
                 stage = 5 * y + x + 1;
                 StreamWriter sw= new StreamWriter("playinfo.txt");
                 sw.WriteLine(mode);
                 sw.WriteLine(stage.ToString());
                 sw.Close();
                 Application.LoadLevel("game");
             }
         }
     }
     if (GUI.Button(getRect(0.4, 0.8, 0.2, 0.1), "돌아가기"))
         Application.LoadLevel("mainscreen");
 }
开发者ID:hoki444,项目名称:2014,代码行数:30,代码来源:stageselect.cs

示例4: Main

    private static void Main()
    {
        string[] filePaths = Directory.GetFiles(@"../../");

        List<FileInfo> files = filePaths.Select(path => new FileInfo(path)).ToList();

        var sorted =
            files.OrderBy(file => file.Length).GroupBy(file => file.Extension).OrderByDescending(group => group.Count()).ThenBy(group => group.Key);
    
        string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

        StreamWriter writer = new StreamWriter(desktop + "/report.txt");

        using (writer)
        {
            foreach (var group in sorted)
            {
                writer.WriteLine(group.Key);

                foreach (var y in group)
                {
                    writer.WriteLine("--{0} - {1:F3}kb", y.Name, y.Length / 1024.0);
                }
            } 
        }       

        System.Diagnostics.Process.Start(desktop + "/report.txt");
    }
开发者ID:zhecho1215,项目名称:HomeWorks,代码行数:28,代码来源:DirectoryTraversal.cs

示例5: WriteLog

            public static void WriteLog(string ex)
            {
                string ErrorLog_OnOff = "on";
                if (ErrorLog_OnOff == "" || ErrorLog_OnOff == "on")
                {
                try
                {

                    string FilePath = "ErrorReport\\";
                    if (!Directory.Exists(FilePath))
                    {
                        Directory.CreateDirectory(FilePath);
                    }
                    string FileName = FilePath + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                    if (GetFileSize(FileName) > 1024 * 1024 * 3)
                    {
                        CopyToBak(FileName);
                    }
                    StreamWriter MySw = new StreamWriter(FileName, true);
                    MySw.WriteLine("错误信息 : " + ex);
                    MySw.WriteLine("\r\n*****************mxy*Error*Report*****************\r\n");
                    MySw.Close();
                    //MySw.Dispose();
                }
                catch (Exception ex1)
                {
                    throw new Exception(ex1.ToString());
                }
                }
            }
开发者ID:paulwangxp,项目名称:MDSoft,代码行数:30,代码来源:ErrorLog.cs

示例6: Main

    static void Main()
    {
        string filePath = "file.txt";
        int linesToWrite = 33;

        // writing to a file
        StreamWriter writeTheFile = new StreamWriter(filePath);
        using (writeTheFile)
        {
            for (int i = 1; i <= linesToWrite; i++)
            {
                if (i % 2 == 0)
                {
                    writeTheFile.WriteLine("I am even line. I am invincible!");
                }
                else
                {
                    writeTheFile.WriteLine("I am odd line. If you don't see me I am deleted ;(!");
                }
            }
        }

        Console.WriteLine("The file has been created!");

        // deleting odd lines
        string result = "";
        int lineCounter = 1;
        StreamReader reader = new StreamReader(filePath);
        using (reader)
        {
            string readSingleLine = reader.ReadLine();

            while (readSingleLine != null)
            {
                if (lineCounter % 2 == 0)
                {
                    result += readSingleLine;
                    result += "\r\n";
                }
                //else                               to add empty line at deleted one
                //{
                //    result += "\r\n";
                //}

                readSingleLine = reader.ReadLine();
                lineCounter++;
            }
        }

        Console.WriteLine("Odd lines deleted!");

        // rewriting the file
        StreamWriter overwriteFile = new StreamWriter(filePath);
        using (overwriteFile)
        {
            overwriteFile.Write(result);
        }

        OpenResultFile(filePath);
    }
开发者ID:TishoAngelov,项目名称:TelerikAcademy,代码行数:60,代码来源:DeleteOddLines.cs

示例7: Main

    static void Main()
    {
        string path = Console.ReadLine();

        var extentions = new SortedDictionary<string, Dictionary<string, double>>();
        DirectoryInfo directory = new DirectoryInfo(path);

        foreach (var file in directory.GetFiles())
        {
            if (extentions.ContainsKey(file.Extension))
            {
                extentions[file.Extension].Add("--" + file.Name + " - ", file.Length);
            }
            else
            {
                extentions.Add(file.Extension, new Dictionary<string, double> { { file.Name, file.Length } });
            }
        }

        var result = extentions.OrderByDescending(p => p.Value.Count).ThenBy(p => p.Key);
        using (var writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/report.txt"))
        {
            foreach (var extention in result)
            {
                writer.WriteLine(extention.Key);
                var sortedSubDict = extention.Value.OrderBy(p => p.Value);
                foreach (var pair in sortedSubDict)
                {
                    writer.WriteLine("--{0} - {1:F3}kb", pair.Key, pair.Value / 1024);
                }
            }
        }
    }
开发者ID:f0rward0,项目名称:Csharp,代码行数:33,代码来源:Program.cs

示例8: Main

    static void Main()
    {
        Console.WriteLine("This program concatenates two text files into another text file.");
        StreamWriter writer = new StreamWriter("..\\..\\Writer");
        using (writer)
        {
            StreamReader file1 = new StreamReader("..\\..\\02. Concatenate text files.cs");
            using (file1)
            {
                string file1Reader = file1.ReadLine();
                while (file1Reader != null)
                {

                    writer.WriteLine(file1Reader);
                    file1Reader = file1.ReadLine();
                }

            }

            StreamReader file2 = new StreamReader("..\\..\\Properties\\AssemblyInfo.cs");
            using (file2)
            {
                string file2Reader = file2.ReadLine();
                while (file2Reader != null)
                {
                    writer.WriteLine(file2Reader);
                    file2Reader = file2.ReadLine();
                }
            }
        }
        Console.WriteLine("You can find all results and text files in the folders of the different projects!");
    }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:32,代码来源:02.+Concatenate+text+files.cs

示例9: UpdateGist

    public static XDocument UpdateGist(string id, string description, string filename, string body)
    {
        var xml = new XElement("gist",
            new XElement("description", description),
            new XElement("public", true),
            new XElement("files",
                new XElement(filename,
                    new XElement("content", body)
                )
            )
        );
        var json = JsonConvert.SerializeXNode(xml, Formatting.Indented, true);

        var request = WebRequest.Create(string.Format(updateGistUrl, id)) as HttpWebRequest;
        request.AllowAutoRedirect = false;
        request.Method = "PATCH";
        using (var postStream = new StreamWriter(request.GetRequestStream()))
        {
            postStream.Write(json);
            postStream.WriteLine();
            postStream.WriteLine();
        }
        using (var response = request.GetResponse())
        {
            using (var responseStream = new StreamReader(response.GetResponseStream()))
            {
                var responseJson = responseStream.ReadToEnd();

                var responseXml = JsonConvert.DeserializeXNode(responseJson, "gist") as XDocument;
                return responseXml;
            }
        }            
    }
开发者ID:wudlng,项目名称:codeuml,代码行数:33,代码来源:GistHelper.cs

示例10: Main

    static void Main()
    {
        try
        {
            using (StreamReader readerOne = new StreamReader("textfile1.txt"), readerTwo = new StreamReader("textfile2.txt"))
            {
                using (StreamWriter writer = new StreamWriter("result.txt"))
                {
                    string line;
                    while ((line = readerOne.ReadLine()) != null)
                    {
                        writer.WriteLine(line);
                    }

                    while ((line = readerTwo.ReadLine()) != null)
                    {
                        writer.WriteLine(line);
                    }
                }
            }
        }
        catch (IOException e)
        {
            Console.WriteLine("I/O error!");
        }
    }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:26,代码来源:ConcatenateFiles.cs

示例11: Main

 public static void Main(String[] args)
 {
     TcpListener server = new TcpListener(int.Parse(args[0]));
     server.Start();
     TcpClient client = server.AcceptTcpClient();
     NetworkStream stream = client.GetStream();
     StreamReader reader = new StreamReader(stream);
     String s = reader.ReadLine();
     String[] strings = s.Split();
     StreamWriter writer;
     if (strings[0] != "GET") {
       writer = new StreamWriter(stream);
       writer.WriteLine
              ("HTTP/1.0 501 Not Implemented");
       writer.WriteLine();
     } else {
        String filename = strings[1];
        while(reader.ReadLine() != "");
        writer = new StreamWriter(stream);
        writer.WriteLine("HTTP/1.0 200 OK");
        writer.WriteLine("Content-type: text/plain");
        writer.WriteLine();
        StreamReader file = new StreamReader(filename);
        String z = file.ReadToEnd();
        writer.WriteLine(z);
        writer.Flush();
        writer.Close();
        file.Close();
     }
     client.Close();
     stream.Close();
     reader.Close();
     writer.Close();
     server.Stop();
 }
开发者ID:JnS-Software-LLC,项目名称:CSC153,代码行数:35,代码来源:VerySimpleWebServer.cs

示例12: Main

    static void Main(string[] args)
    {
        string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
        string pathTraverse = Console.ReadLine();

        //get all the files info in a list
        string[] filePaths = Directory.GetFiles(String.Format(@"{0}",pathTraverse));
        List<FileInfo> fileInfos = filePaths.Select(p => new FileInfo(p)).ToList();

        //sort the list
        var sorted = fileInfos.OrderByDescending(file => file.Length).GroupBy(file => file.Extension).
            OrderByDescending(group => group.Count()).ThenBy(group => group.Key);

        //create file report.txt
        using (StreamWriter reportWriter = new StreamWriter(desktopPath + "/report.txt"))
        {
            foreach (var group in sorted)
            {
                reportWriter.WriteLine(group.Key);
                foreach (var info in group)
                {
                    double sizeKB = info.Length/ 1024.0;
                    reportWriter.WriteLine(String.Format("--{0} - {1:0.00}kb",info.Name,sizeKB));
                }
            }
        }
    }
开发者ID:sokito,项目名称:Softuni,代码行数:27,代码来源:TraverseDirectory.cs

示例13: logException

    public static bool logException(Exception exception)
    {
        bool status = false;
        string  logFilePathName = GetDefaultPath();
        if (!File.Exists(logFilePathName))
        {
            if (CheckForDirectory(logFilePathName))
            {
                FileStream fileStream = new FileStream(logFilePathName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                fileStream.Close();
            }
        }
        try
        {
            StreamWriter streamWriter = new StreamWriter(logFilePathName, true);

            streamWriter.WriteLine("Date        : " + DateTime.Now.ToLongTimeString());
            streamWriter.WriteLine("Time        : " + DateTime.Now.ToShortDateString());
            streamWriter.WriteLine("Error       : " + exception.Message.ToString().Trim());
            streamWriter.WriteLine("Type        : " + exception.GetType().ToString());
            streamWriter.WriteLine("********************************************************");

            streamWriter.Flush();
            streamWriter.Close();

            status = true;
        }
        catch (Exception ex)
        {
            //There was an error return null.
            Console.WriteLine(ex.ToString());
        }

        return status;
    }
开发者ID:westrada-cc,项目名称:SOA-phantom-power,代码行数:35,代码来源:Logger.cs

示例14: Main

    static void Main()
    {
        
        StreamReader reader = new StreamReader("../../Poem.txt");
        StreamWriter writer = new StreamWriter("../../NewPoem.txt");
        using (reader)
        {
            using (writer)
            {
                string line = reader.ReadLine();
                int lineNumber = 1;
                while (line != null)
                {
                    if (lineNumber == 5
                        || lineNumber == 10)
                    {
                        writer.WriteLine();
                        lineNumber++;
                        line = reader.ReadLine();
                        continue;
                    }
                    writer.WriteLine("{0}. {1}", lineNumber, line);
                    lineNumber++;
                    line = reader.ReadLine();
                }
            }
        }
        // Guess the poem.

    }
开发者ID:k1r1L,项目名称:Soft-Uni-Homeworks,代码行数:30,代码来源:LineNumbers.cs

示例15: Main

    static void Main()
    {
        StreamWriter writer = new StreamWriter(@"..\..\thirdText.txt");

        using (writer)
        {
            using (StreamReader firstReader = new StreamReader(@"..\..\firstText.txt"))
            {
                string line = firstReader.ReadLine();

                while (line != null)
                {
                    writer.WriteLine(line);
                    line = firstReader.ReadLine();
                }
            }

            using (StreamReader secondReader = new StreamReader(@"..\..\secondText.txt"))
            {
                string line = secondReader.ReadLine();

                while (line != null)
                {
                    writer.WriteLine(line);
                    line = secondReader.ReadLine();
                }
            }
        }

        Console.WriteLine("Concatenated text files is done!");
    }
开发者ID:iliantova,项目名称:Telerik-Homework,代码行数:31,代码来源:ConcaTextFiles.cs


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