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


C# StreamWriter类代码示例

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


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

示例1: 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:GeroL,项目名称:MOSA-Project,代码行数:33,代码来源:Execution+Timer.cs

示例2: MeshToFile

 public static void MeshToFile(MeshFilter mf, string filename)
 {
     using (StreamWriter sw = new StreamWriter(filename))
     {
         sw.Write(MeshToString(mf));
     }
 }
开发者ID:afeike01,项目名称:PlanetRTS,代码行数:7,代码来源:ObjExporter.cs

示例3: Init

    private void Init() {

        if (!File.Exists(file)){
            myFs = new FileStream(file, FileMode.Create);
        }
        mySw = new StreamWriter(file, true, System.Text.Encoding.GetEncoding("utf-8"));
    }    
开发者ID:baowencheng,项目名称:simplecs,代码行数:7,代码来源:GameLog.cs

示例4: ReplaceFile

 public static Dictionary<string, int> ReplaceFile(string FilePath, string NewFilePath)
 {
     Dictionary<string, int> word_freq = new Dictionary<string, int>();
        using (StreamReader vReader = new StreamReader(FilePath))
        {
       using (StreamWriter vWriter = new StreamWriter(NewFilePath))
       {
          int vLineNumber = 0;
          while (!vReader.EndOfStream)
          {
             string vLine = vReader.ReadLine();
             string[] words = SplitLine(vLine);
             foreach (string s in words) {
                 try {
                     word_freq[s]++;
                     //Console.WriteLine("=> {0}", s);
                 } catch (Exception ex) {
                     word_freq[s] = 1;
                 }
             }
             vWriter.WriteLine(ReplaceLine(vLine, vLineNumber++));
          }
       }
        }
        return word_freq;
 }
开发者ID:walrus7521,项目名称:code,代码行数:26,代码来源:Bible.cs

示例5: Main

 static void Main()
 {
     try
     {
         StreamReader reader = new StreamReader(@"D:\newfile.txt");
         List<string> newText = new List<string>();
         using (reader)
         {
             string line = reader.ReadLine();
             int lineNumber = 0;
             while (line != null)
             {
                 lineNumber++;
                 newText.Add(lineNumber.ToString() + ". " + line);
                 line = reader.ReadLine();
             }
         }
         StreamWriter writer = new StreamWriter(File.Open(@"D:\ResultIs.txt",FileMode.Create));
         using (writer)
         {
             for (int i = 0; i < newText.Count; i++)
             {
                 writer.WriteLine(newText[i]);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:32,代码来源:ReadFileAndInsertLineNum.cs

示例6: Main

 static void Main()
 {
     using (StreamReader input = new StreamReader("../../1.txt"))
         using (StreamWriter output = new StreamWriter("../../2.txt"))
             for (string line; (line = input.ReadLine()) != null; )
                 output.WriteLine(line.Replace("start", "finish"));
 }
开发者ID:martinangelos88,项目名称:CSharpProject,代码行数:7,代码来源:7.ReplaceSubString1To2.cs

示例7: ConcatenateTwoStrings

    static void ConcatenateTwoStrings(string firstStr, string secondStr)
    {
        bool exist = false;

        try
        {
            exist = File.Exists(@"../../result.txt");
            StreamWriter writer = new StreamWriter(@"../../result.txt");
            using (writer)
            {
                writer.Write(firstStr + Environment.NewLine + secondStr);
            }
        }
        catch
        {
            Console.WriteLine("Something went wrong! Check file paths or file contents.");
        }
        finally
        {
            if (exist)
                Console.WriteLine("Text file \"result.txt\" re-created!");
            else
                Console.WriteLine("Text file \"result.txt\" created!");
        }
    }
开发者ID:NikolovNikolay,项目名称:Telerik-Homeworks,代码行数:25,代码来源:ConcatenateTwoInOne.cs

示例8: Main

    static void Main()
    {
        // Reads some text file
        StreamReader read = new StreamReader("file.txt");
        using (read)
        {
            // Creates an empty list and fill it
            string line = read.ReadLine();
            List<string> list = new List<string>();
            for (int l = 0; line != null; l++)
            {
                // Adds each one word from the file in the list
                list.Add(line);

                // Reads the next line
                line = read.ReadLine();
            }

            // Sorting the list
            list.Sort();

            // Write the sorted list in some output file
            StreamWriter write = new StreamWriter("output.txt");
            using (write)
            {
                foreach (var word in list)
                {
                    write.WriteLine(word);
                }
            }
        }
    }
开发者ID:Termininja,项目名称:TelerikAcademy,代码行数:32,代码来源:ListOfStrings.cs

示例9: UglyNumbers

    public UglyNumbers()
    {
        input = new StreamReader("dir/2008/Round1C/B/B-large.in");
        output = new StreamWriter("dir/2008/Round1C/B/B-large.out");

        this.N = int.Parse(input.ReadLine());
    }
开发者ID:KitKat10,项目名称:Google-Code-Jam,代码行数:7,代码来源:B.cs

示例10: Main

    public static int Main(string[] args)
    {
        TextWriter writer = Console.Out;
        string method_name = null;
        string formatter = null;
        bool show_help = false;

        var os = new OptionSet () {
            { "formatter=", "Source code formatter. Valid values are: 'csharp-coregraphics'", v => formatter = v },
            { "out=", "Source code output", v => writer = new StreamWriter (v) },
            { "h|?|help", "Displays the help", v => show_help = true },
        };

        var svg = os.Parse (args);
        string path = (svg.Count > 1) ? String.Concat (svg) : svg [0];

        if (show_help)
            Usage (os, null);

        var parser = new SvgPathParser ();

        switch (formatter) {
        case "csharp-coregraphics":
        case "cs-cg":
            parser.Formatter = new CSharpCoreGraphicsFormatter (writer);
            break;
        default:
            Usage (os, "error: unkown {0} code formatter", formatter);
            break;
        }

        parser.Parse (path, method_name);
        return 0;
    }
开发者ID:joehanna,项目名称:svgpath2code,代码行数:34,代码来源:svgpath2code.cs

示例11: 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

示例12: WordCount

    private static void WordCount(string text)
    {
        string[] checker = text.ToLower().Split(new char[] { ' ', '.', ',', '!', '?', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        Array.Sort(checker);
        StreamWriter write = new StreamWriter("..\\..\\Output.txt");
        using (write)
        {
            for (int i = 0; i < checker.Length; i++)
            {
                string current = checker[i];
                int count = 0;
                for (int j = i; j < checker.Length; j++)
                {
                    if (current != checker[j])
                    {
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
                i = i + count - 1;
                write.WriteLine("{0,30} is present {1,2} times inside the text", current, count);

            }
        }
    }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:28,代码来源:WordCounter.cs

示例13: AddToHighScore

    void AddToHighScore(float time)
    {
        highScoreList.Add(new KeyValuePair<string, float>(userName, time));

        highScoreList.Sort((firstPair, nextPair) =>
        {
            return firstPair.Value.CompareTo(nextPair.Value);
        });

        //Make sure highScoreList doesn't have too many elements
        if (highScoreList.Count > maxScoreCount)
        {
            //Remove the last element
            highScoreList.RemoveAt(highScoreList.Count - 1);
        }

        StreamWriter file=new StreamWriter(filePath);

        //Write the updated high score list to the file
        for (int i = 0; i < highScoreList.Count; i++) //Iterate through highScoreList
        {
            file.WriteLine(highScoreList[i].Key.ToString() + ":" + highScoreList[i].Value.ToString());
        }

        file.Close();
    }
开发者ID:Raful,项目名称:Hoverboard,代码行数:26,代码来源:HighScore.cs

示例14: Main

	static void Main (string [] args)
	{
		int i = 0;

		while (args [i].StartsWith ("-")){
			if (args [i] == "-debug")
				debug = true;
			if (args [i] == "-headers")
				headers = true;
			if (args [i] == "-header")
				header = args [++i];
			i++;
		}
		
		c = new TcpClient (args [i], Int32.Parse (args [i+1]));
		c.ReceiveTimeout = 1000;
		ns = c.GetStream ();
		
		sw = new StreamWriter (ns);
		sr = new StreamReader (ns);

		string host = args [i];
		if (args [i+1] != "80")
			host += ":" + args [i+1];
		send (String.Format ("GET {0} HTTP/1.1\r\nHost: {1}\r\n\r\n", args [i+2], host));

		MemoryStream ms = new MemoryStream ();
		
		try {
			byte [] buf = new byte [1024];
			int n;
			
			while ((n = ns.Read (buf, 0, 1024)) != 0){
				ms.Write (buf, 0, n);
			}
		} catch {}

		ms.Position = 0;
		sr = new StreamReader (ms);

		string s;
		
		while ((s = sr.ReadLine ()) != null){
			if (s == ""){
				if (headers)
					return;
				
				string x = sr.ReadToEnd ();
				Console.Write (x);
				break;
			}  else {
				if (debug || headers)
					Console.WriteLine (s);
				if (header != null && s.StartsWith (header)){
					Console.WriteLine (s);
					return;
				}
			}
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:60,代码来源:rtest.cs

示例15: WriteTheFile

 static void WriteTheFile(StringBuilder sb)
 {
     using (StreamWriter writer = new StreamWriter(@"..\..\test.txt"))
     {
         writer.Write(sb);
     }
 }
开发者ID:enchev-93,项目名称:Telerik-Academy,代码行数:7,代码来源:PrefixTest.cs


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