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


C# StreamWriter.Write方法代码示例

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


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

示例1: CreateLog

    public void CreateLog(Exception ex)
    {
      try
      {
        using (TextWriter writer = new StreamWriter(_filename, false))
        {
          writer.WriteLine("Crash Log: {0}", _crashTime);

          writer.WriteLine("= System Information");
          writer.Write(SystemInfo());
          writer.WriteLine();

          writer.WriteLine("= Disk Information");
          writer.Write(DriveInfo());
          writer.WriteLine();

          writer.WriteLine("= Exception Information");
          writer.Write(ExceptionInfo(ex));
					writer.WriteLine();
					writer.WriteLine();

					writer.WriteLine("= MediaPortal Information");
					writer.WriteLine();
        	IList<string> statusList = ServiceRegistration.Instance.GetStatus();
        	foreach (string status in statusList)
        		writer.WriteLine(status);
        }
      }
      catch (Exception e)
      {
        Console.WriteLine("UiCrashLogger crashed:");
        Console.WriteLine(e.ToString());
      }
    }
开发者ID:chekiI,项目名称:MediaPortal-2,代码行数:34,代码来源:ServerCrashLogger.cs

示例2: SaveLastCode

        private void SaveLastCode()
        {
            string filename = Path.Combine(localPath, "TestApp.os");
            using (var writer = new StreamWriter(filename, false, Encoding.UTF8))
            {
                // первой строкой запишем имя открытого файла
                writer.Write("//");  // знаки комментария, чтобы сохранить код правильным
                writer.WriteLine(_currentDocPath);
                // второй строкой - признак изменённости
                writer.Write("//");
                writer.WriteLine(_isModified);

                args.Text = args.Text.TrimEnd('\r', '\n');

                // запишем аргументы командной строки
                writer.Write("//");
                writer.WriteLine(args.LineCount);

                for (var i = 0; i < args.LineCount; ++i )
                {
                    string s = args.GetLineText(i).TrimEnd('\r', '\n');
                    writer.Write("//");
                    writer.WriteLine(s);
                }

                // и потом сам код
                writer.Write(txtCode.Text);
            }
        }
开发者ID:Shemetov,项目名称:OneScript,代码行数:29,代码来源:MainWindow.xaml.cs

示例3: extractFeatures

        // Extract and store features
        public static void extractFeatures(string folderPath, int M, string output = "articles.feat")
        {
            DocCollection collection = new DocCollection();

            // Collect all files
            foreach (string filepath in Directory.GetFiles(folderPath, "*.txt"))
            {
                string content = File.ReadAllText(filepath);
                collection.collect(content);
            }

            List<DocVector> docVect = collectionProcessing(collection, 20);

            // Store features
            using (StreamWriter writer = new StreamWriter(output, false))
            {
                writer.WriteLine(Directory.GetFiles(folderPath, "*.txt").Count()); // Number of files
                writer.WriteLine(M); // Number of keywords

                // Store bag of words
                for (int i = 0; i < M; ++i)
                    writer.Write(keywords[i] + " ");
                writer.WriteLine();

                // Store feature for each document
                foreach (DocVector vector in docVect)
                {
                    for (int i = 0; i < M; ++i)
                        writer.Write(vector.Tf_idf[i] + " ");
                    writer.WriteLine();
                }
            }
        }
开发者ID:Neo20067,项目名称:doc-clustering,代码行数:34,代码来源:VectorSpaceModel.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //获得串口参数配置文件的路径
            string CfgFilePath = Application.StartupPath + "\\ConfigFile\\SerialPortCfg";

            //创建写文件流
            StreamWriter sw = new StreamWriter(CfgFilePath, false);

            //将串口参数写入文件
            sw.Write(comboBox1.SelectedItem + "\r\n");
            sw.Write(comboBox2.SelectedItem + "\r\n");
            sw.Write(comboBox3.SelectedItem + "\r\n");
            sw.Write(comboBox4.SelectedItem + "\r\n");
            sw.Write(comboBox5.SelectedItem + "\r\n");

            //关闭流
            sw.Close();

            //创建读文件流
            StreamReader sr = new StreamReader(CfgFilePath);

            //显示串口参数
            label6.Text = sr.ReadLine();
            label7.Text = sr.ReadLine();
            label8.Text = sr.ReadLine();
            label9.Text = sr.ReadLine();
            label10.Text = sr.ReadLine();

            //关闭流
            sr.Close();
            MessageBox.Show(this, "设置成功。   ", "消息",
                MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.Close();   //关串口参数设置窗体
        }
开发者ID:LeeDong1993,项目名称:EmbeddedClassRomm,代码行数:35,代码来源:Form9.cs

示例5: WritePoints

        private static void WritePoints(StreamWriter writer, IEnumerable<Point> points, int count)
        {
            int attributes = 0, index = 0;

            var first = points.FirstOrDefault();

            if (first.Attributes != null)
            {
                attributes = first.Attributes.Length;
            }

            writer.WriteLine("{0} {1} {2} {3}", count, 2, attributes, 1);

            foreach (var item in points)
            {
                // Vertex number, x and y coordinates.
                writer.Write("{0} {1} {2}", index, item.X.ToString(Util.Nfi), item.Y.ToString(Util.Nfi));

                // Write attributes.
                for (int j = 0; j < attributes; j++)
                {
                    writer.Write(" {0}", item.Attributes[j].ToString(Util.Nfi));
                }

                // Write the boundary marker.
                writer.WriteLine(" {0}", item.Boundary);

                index++;
            }
        }
开发者ID:RegrowthStudios,项目名称:VoxelRTS,代码行数:30,代码来源:GeometryWriter.cs

示例6: Parse

 public string Parse(Stream stream, Dictionary<string, string> settings)
 {
     var source = Extract(stream);
     using (var output = new MemoryStream())
     using (var writer = new StreamWriter(output))
     {
         writer.AutoFlush = true;
         stream.Position = Bom.GetCursor(stream);
         byte[] buffer = new byte[1];
         while (stream.Read(buffer, 0, 1) > 0)
         {
             if (source.Any(p => p.IsWithin(stream.Position)))
             {
                 foreach (var symbol in source.Where(p => p.Cursor == stream.Position))
                 {
                     if (!settings.ContainsKey(symbol.Key))
                     {
                         throw new KeyNotFoundException($"A setting has not been provided for key {symbol.Key} in the json file");
                     }
                     writer.Write(new[] {Convert.ToChar(buffer[0])});
                     stream.Position += symbol.Length;
                     writer.Write(settings[symbol.Key]);
                 }
             }
             else
             {
                 writer.Write(_encoding.GetChars(buffer));
             }
         }
         return _encoding.GetString(output.ToArray());
     }
 }
开发者ID:RossJayJones,项目名称:figs.net,代码行数:32,代码来源:DefaultConfigurationParser.cs

示例7: Compile

        public void Compile(Generator generator, string outputFile)
        {
            // Generate compiletime environment
            var labels = _functionEnvironment.GetFunctionNames().ToDictionary(funName => funName, funName => Label.Fresh());
            var compilationEnvironment = new CompilationEnvironment(labels);

            // Compile expression
            _expression.Compile(compilationEnvironment, generator);
            generator.Emit(Instruction.PrintI);
            generator.Emit(Instruction.Stop);

            // Compile functions
            foreach (var functionDefinition in _functionEnvironment.GetFunctions())
            {
                compilationEnvironment = new CompilationEnvironment(labels);
                functionDefinition.Compile(compilationEnvironment, generator);
            }

            //  Generate bytecode at and print to file
            generator.PrintCode();
            var bytecode = generator.ToBytecode();
            using (TextWriter writer = new StreamWriter(outputFile))
            {
                foreach (var b in bytecode)
                {
                    writer.Write(b);
                    writer.Write(" ");
                }
            }
        }
开发者ID:ondfisk,项目名称:Expressions,代码行数:30,代码来源:Program.cs

示例8: RunTests

        public static void RunTests()
        {
            StreamWriter results = new StreamWriter(@"../../results.txt");
            bool testcaseResult;
            results.WriteLine("-------------- Custom Handler\n");
            for (var i = 0; i < Testcases.Length; i++)
            {
                var sw = Stopwatch.StartNew();
                testcaseResult = CustomHandler.CheckText(Testcases[i]);
                sw.Stop();
                results.Write("Testcase N{0}: {1}\n" +
                              "Solution runtime summary: {2} ticks ({3} ms)\n\n",
                              i + 1, testcaseResult, sw.ElapsedTicks, sw.ElapsedMilliseconds);
            }

            results.WriteLine("-------------- Regex Handler\n");
            for (var i = 0; i < Testcases.Length; i++) {
                var sw = Stopwatch.StartNew();
                testcaseResult = RegexHandler.CheckText(Testcases[i]);
                sw.Stop();
                results.Write("Testcase N{0}: {1}\n" +
                              "Solution runtime summary: {2} ticks ({3} ms)\n\n",
                              i + 1, testcaseResult, sw.ElapsedTicks, sw.ElapsedMilliseconds);
            }

            results.Close();
        }
开发者ID:Praytic,项目名称:csharp-basics,代码行数:27,代码来源:ActionManager.cs

示例9: Main

 static void Main(string[] args)
 {
     using (StreamReader reader = new StreamReader(@"c:\files\inputFile.txt"))
     using (StreamWriter writer = new StreamWriter(@"c:\files\outputFile.txt", false))
     {
         int position = 0;
         while (!reader.EndOfStream)
         {
             char[] buffer = new char[16];
             int charactersRead = reader.ReadBlock(buffer, 0, 16);
             writer.Write("{0}: ", String.Format("{0:x4}", position));
             position += charactersRead;
             for (int i = 0; i < 16; i++)
             {
                 if (i < charactersRead)
                 {
                     string hex = String.Format("{0:x2}", (byte)buffer[i]);
                     writer.Write(hex + " ");
                 }
                 else
                     writer.Write("   ");
                 if (i == 7) { writer.Write("-- "); }
                 if (buffer[i] < 32 || buffer[i] > 250) { buffer[i] = '.'; }
             }
             string bufferContents = new string(buffer);
             writer.WriteLine("   " + bufferContents.Substring(0, charactersRead));
         }
     }
 }
开发者ID:HeberAlvarez,项目名称:HeadFirst,代码行数:29,代码来源:Program.cs

示例10: Write

 internal void Write(StreamWriter sw, string nodeName)
 {
     sw.Write(string.Format("<{0}", nodeName));
     XmlHelper.WriteAttribute(sw, "r:id", this.id);
     sw.Write(">");
     sw.Write(string.Format("</{0}>", nodeName));
 }
开发者ID:89sos98,项目名称:npoi,代码行数:7,代码来源:CT_ExternalReferences.cs

示例11: Archive_Summary_Click

        protected void Archive_Summary_Click(object sender, EventArgs e)
        {
            String strDestinationFile;
            strDestinationFile = "C:\\output.txt";
            TextWriter tw = new StreamWriter(strDestinationFile);
            //tw.WriteLine("Hello");

            for (int x = 0; x < ProductsGrid.Rows.Count; x++)
            {
                for (int y = 0; y < ProductsGrid.Rows[0].Cells.Count; y++)
                {
                    tw.Write(ProductsGrid.Rows[x].Cells[y].Text);
                    if (y == 0)
                    {
                        Response.Write(ProductsGrid.Rows[0].Cells[0].Text);
                    }
                        if (y != ProductsGrid.Rows[0].Cells.Count - 1)
                    {
                        tw.Write(", ");
                    }
                }
                tw.WriteLine();
            }
            tw.Close();
        }
开发者ID:iammasariya,项目名称:Retail-Management-System,代码行数:25,代码来源:StoreSummary.aspx.cs

示例12: Main

        static void Main()
        {
            StreamReader reader = new StreamReader("../../person.txt");
            StreamWriter writer = new StreamWriter("person.xml");
            List<string> values = new List<string>();
            List<string> tags = new List<string>() { "name", "address", "phone" };

            using (reader)
            {
                while (!reader.EndOfStream)
                {
                    var currValue = reader.ReadLine();
                    values.Add(currValue);
                }
            }

            using (writer)
            {
                writer.Write("<?xml version=\"1.0\"?>");
                writer.Write("<person>");
                for (int i = 0; i < values.Count; i++)
                {
                    writer.Write(string.Format("<{0}>{1}</{0}>", tags[i], values[i]));
                }
                writer.Write("</person>");
            }
        }
开发者ID:hristo-iliev,项目名称:TelerikHW,代码行数:27,代码来源:Program.cs

示例13: ExportDataGridToCSV

        /// <summary>
        /// Export the data from datatable to CSV file
        /// </summary>
        /// <param name="grid"></param>
        public static void ExportDataGridToCSV(DataGridView dgv)
        {
            string path = "";

            //File info initialization
            path = path + DateTime.Now.ToString("yyyyMMddhhmmss");
            path = path + ".csv";

            System.IO.FileStream fs = new FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, new System.Text.UnicodeEncoding());
            //Tabel header
            for (int i = 0; i < dgv.Columns.Count; i++)
            {
                sw.Write(dgv.Columns[i].HeaderText);
                sw.Write("\t");
            }
            sw.WriteLine("");
            //Table body

            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                for (int j = 0; j < dgv.Rows[i].Cells.Count; j++)
                {
                    sw.Write(DelQuota(dgv[j,i].Value.ToString()));
                    sw.Write("\t");
                }
                sw.WriteLine("");
            }
            sw.Flush();
            sw.Close();
        }
开发者ID:kevinfyc,项目名称:yoga,代码行数:35,代码来源:Untils.cs

示例14: Main

 static void Main(string[] args)
 {
     string fileName = args[0];
     XmlDocument doc = new XmlDocument();
     string outputFile = Path.ChangeExtension(fileName, ".txt");
     TextWriter writer = new StreamWriter(outputFile);
     writer.WriteLine("Error\tReads\tRowCounts\tQuery\tDuration\tWrites\t");
     doc.Load(fileName);
     foreach(XmlNode node in doc.GetElementsByTagName("Event"))
     {
         if (node.Attributes["name"] == null || node.Attributes["name"].Value != "SQL:BatchCompleted")
             continue;
         foreach (XmlNode child in node.ChildNodes)
         {
             if (child.Name != "Column")
                 continue;
             switch (child.Attributes["name"].Value)
             {
                 case "Duration":
                 case "Reads":
                 case "RowCounts":
                 case "Error":
                 case "TextData":
                 case "Writes":
                     writer.Write(child.InnerText);
                     writer.Write('\t');
                     break;
             }
         }
         writer.WriteLine();
     }
     writer.Close();
 }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:33,代码来源:Program.cs

示例15: AppendResultsToFile

        public void AppendResultsToFile(String Name, double TotalTime)
        {
            FileStream file;
            file = new FileStream(Name, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(file);

            sw.Write("***************************************\n");

            sw.Write("Total  | No Subs| %Total |%No Subs| Name\n");

            foreach (CNamedTimer NamedTimer in m_NamedTimerArray)
            {
                if (NamedTimer.GetTotalSeconds() > 0)
                {
                    String OutString;

                    OutString = String.Format("{0:0.0000}", NamedTimer.GetTotalSeconds())
                        + " | " + String.Format("{0:0.0000}", NamedTimer.GetTotalSecondsExcludingSubroutines())
                        + " | " + String.Format("{0:00.00}", System.Math.Min(99.99, NamedTimer.GetTotalSeconds() / TotalTime * 100)) + "%"
                        + " | " + String.Format("{0:00.00}", NamedTimer.GetTotalSecondsExcludingSubroutines() / TotalTime * 100) + "%"
                        + " | "
                        + NamedTimer.m_Name;

                    OutString += " (" + NamedTimer.m_Counter.ToString() + ")\n";
                    sw.Write(OutString);
                }
            }

            sw.Write("\n\n");

            sw.Close();
            file.Close();
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:33,代码来源:Execution+Timer.cs


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