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


C# StreamReader.Close方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        if (args.Length < 2) {
            Console.WriteLine("Usage: BenchSgmlReader.exe filename iterations");
            return;
        }

        var streamReader = new StreamReader(args[0]);
        string text = streamReader.ReadToEnd();
        streamReader.Close();

        int n = int.Parse(args[1]);

        var start = DateTime.Now;
        for (int i = 0; i < n; i++) {
            SgmlReader sgmlReader = new SgmlReader();
            sgmlReader.DocType = "HTML";
            sgmlReader.WhitespaceHandling = WhitespaceHandling.All;
            //sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
            sgmlReader.InputStream = new StringReader(text);

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.XmlResolver = null;
            doc.Load(sgmlReader);
        }
        var stop = DateTime.Now;

        var duration = stop - start;
        Console.WriteLine("{0} s", (duration.TotalMilliseconds / 1000.0).ToString(CultureInfo.InvariantCulture));
    }
开发者ID:FrameworkBy,项目名称:html-parsers-benchmark,代码行数:31,代码来源:BenchSgmlReader.cs

示例2: btnInstall_Click

    protected void btnInstall_Click(object sender, EventArgs e)
    {
        string ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\{0}.mdb;",
                txtDatabaseName.Text);
        OleDbConnection OConn = new OleDbConnection(ConnectionString);
        StreamReader Sr = new StreamReader(Server.MapPath("~/Setup/Scripts/Access.sql"));
        try
        {
            File.Copy(Server.MapPath("~/Setup/Scripts/Blogsa.mdb"), Server.MapPath(string.Format("~/App_Data/{0}.mdb", txtDatabaseName.Text)));

            //Update WebSite Url
            string strUrl = Request.Url.AbsoluteUri.Substring(0
                , Request.Url.AbsoluteUri.IndexOf(Request.Url.AbsolutePath) + (Request.ApplicationPath.Equals("/") ? 0 : Request.ApplicationPath.Length)) + "/";

            OConn.Open();
            while (!Sr.EndOfStream)
            {
                //Create DB
                string Commands = Sr.ReadLine().ToString();
                if (!Commands.StartsWith("/*"))
                {
                    OleDbCommand OComm = new OleDbCommand(Commands, OConn);
                    OComm.ExecuteNonQuery();
                    OComm.Dispose();
                }
            }

            Sr.Close();
            string strLang = (string)Session["lang"];
            string strRedirectPage = String.Format("Completed.aspx?Setup={0}&lang={1}", BSHelper.SaveWebConfig(ConnectionString, "System.Data.OleDb"), strLang);
            Response.Redirect(strRedirectPage, false);
        }
        catch (Exception ex)
        {
            BSLog l = new BSLog();
            l.CreateDate = DateTime.Now;
            l.LogType = BSLogType.Error;
            l.LogID = Guid.NewGuid();
            l.RawUrl = Request.RawUrl;
            l.Source = ex.Source;
            l.StackTrace = ex.StackTrace;
            l.TargetSite = ex.TargetSite;
            l.Url = Request.Url.ToString();
            l.Save();

            divError.Visible = true;
            lblError.Text = ex.Message;
            if (OConn.State == ConnectionState.Open)
            {
                OConn.Close();
            }
            File.Delete(Server.MapPath("~/App_Data/" + txtDatabaseName.Text));
        }
        finally
        {
            if (OConn.State == ConnectionState.Open)
                OConn.Close();
            Sr.Close();
        }
    }
开发者ID:Blogsa,项目名称:blogsa,代码行数:60,代码来源:Access.aspx.cs

示例3: Main

    public static void Main(String[] args)
    {
        StreamReader sr=null;
        StreamWriter sw=null;
        TcpClient client=null;
        TcpListener server=null;
        try {
          //Echo servers listen on port 7
          int portNumber = 7;

          //Echo server first binds to port 7
          server = new TcpListener(portNumber);
          //Server starts listening
          server.Start();

          //Echo server loops forever, listening for clients
          for(;;) {
        Console.WriteLine("Waiting for a connection....");

        //Accept the pending client connection and return a client
        //initialized for communication
        //This method will block until a connection is made
        client = server.AcceptTcpClient();
        Console.WriteLine("Connection accepted.");

        //Make a user-friendly StreamReader from the stream
        sr=new StreamReader(client.GetStream());

        //Make a user-friendly StreamWriter from the stream
        sw=new StreamWriter(client.GetStream());

        String incoming=sr.ReadLine();
        while (incoming!=".") {
        Console.WriteLine("Message received: "+incoming);
        sw.WriteLine(incoming);
        sw.Flush();
        Console.WriteLine("Message Sent back: " + incoming);
        incoming=sr.ReadLine();
        }
        Console.WriteLine("Client sent '.': closing connection.");
        sr.Close();
        sw.Close();
        client.Close();
          }
        } catch (Exception e) {
        Console.WriteLine(e+" "+e.StackTrace);
        } finally {
        if (sr!=null) sr.Close();//check if the stream reader is present - if it is, close it
        if (sw!=null) sw.Close();//check if the stream writer is present - if it is, close it
        if (client!=null) client.Close();
        //Release the port and stop the server
        server.Stop();
        }
    }
开发者ID:JessicaMaxey,项目名称:Networks,代码行数:54,代码来源:EchoServerNoThread.cs

示例4: Main

    public static void Main()
    {
        try
        {
            bool status = true ;
            string servermessage = "" ;
            string clientmessage = "" ;
            TcpListener tcpListener = new TcpListener(8100) ;
            tcpListener.Start() ;
            Console.WriteLine("Server Started") ;

            Socket socketForClient = tcpListener.AcceptSocket() ;
            Console.WriteLine("Client Connected") ;
            NetworkStream networkStream = new NetworkStream(socketForClient) ;
            StreamWriter streamwriter = new StreamWriter(networkStream) ;
            StreamReader streamreader = new StreamReader(networkStream) ;

            while(status)
            {
                if(socketForClient.Connected)
                {
                    servermessage = streamreader.ReadLine() ;
                    Console.WriteLine("Client:"+servermessage) ;
                    if((servermessage== "bye" ))
                    {
                        status = false ;
                        streamreader.Close() ;
                        networkStream.Close() ;
                        streamwriter.Close() ;
                        return ;

                    }
                    Console.Write("Server:") ;
                    clientmessage = Console.ReadLine() ;

                    streamwriter.WriteLine(clientmessage) ;
                    streamwriter.Flush() ;
                }

            }
            streamreader.Close() ;
            networkStream.Close() ;
            streamwriter.Close() ;
            socketForClient.Close() ;
            Console.WriteLine("Exiting") ;
        }
        catch(Exception e)
        {
            Console.WriteLine(e.ToString()) ;
        }
    }
开发者ID:ShiJess,项目名称:CompanyStudy,代码行数:51,代码来源:ChatServer.cs

示例5: loadAllExtensionFiles

 private static void loadAllExtensionFiles()
 {
     if (extensionFiles == null)
     {
         string[] filePaths;
         extensionFiles = new Dictionary<String, String>();
         try
         {
             filePaths = Directory.GetFiles("Resources/Extensions/", "*.cs");
         }
         catch (DirectoryNotFoundException)
         {
             return;
         } 
         foreach (String fileName in filePaths)
         {
             TextReader tr = new StreamReader(fileName);
             String result = "";
             while (tr.Peek() >= 0)
             {
                 result += tr.ReadLine() + "\n";
             }
             extensionFiles.Add(fileName, result);
             tr.Close();
         }
     }
 }
开发者ID:skicean,项目名称:ZhongHuaSanGuoZhi,代码行数:27,代码来源:ExtensionInterface.cs

示例6: Main

    static void Main()
    {
        StreamReader reader = new StreamReader(@"..\..\input.txt");

        List<string> allEvenLines = new List<string>();

        string currLine = null;

        while (1 == 1)
        {
            currLine = reader.ReadLine();//Line1 (1/3/5/7)
            currLine = reader.ReadLine();//Line2 (4/6/8/10)
            if (currLine == null)
            {
                break;
            }
            allEvenLines.Add(currLine);
        }
        reader.Close();

        StreamWriter writer = new StreamWriter(@"..\..\input.txt", false); // after closing the reader
        foreach (string line in allEvenLines)
        {
            writer.WriteLine(line);
        }
        writer.Close();
    }
开发者ID:purlantov,项目名称:TelerikAcademy-4,代码行数:27,代码来源:09.+DeleteAllOddLines.cs

示例7: Main

 static void Main()
 {
     StreamReader reader1 = new StreamReader("../../file1.txt");
     StreamReader reader2 = new StreamReader("../../file2.txt");
     string line1 = reader1.ReadLine();
     string line2 = reader2.ReadLine();
     int sameCount = 0;
     int totalCount = 0;
     while (line1 != null) // * Assume the files have equal number of lines.
     {
         if (line1 == line2)
         {
             sameCount++;
         }
         Console.WriteLine("{0} ?= {1} -> {2}", line1, line2, line1 == line2);
         line1 = reader1.ReadLine();
         line2 = reader2.ReadLine();
         totalCount++;
     }
     reader1.Close();
     reader2.Close();
     Console.WriteLine(new string('=', 25));
     Console.WriteLine("Identic lines: {0}", sameCount);
     Console.WriteLine("Different lines: {0}", totalCount - sameCount);
 }
开发者ID:tima-t,项目名称:Telerik-Academy,代码行数:25,代码来源:Program.cs

示例8: Read

 public static string Read(string path)
 {
     var reader = new StreamReader(path);
     var s = reader.ReadToEnd();
     reader.Close();
     return s;
 }
开发者ID:arahis,项目名称:Swiper,代码行数:7,代码来源:Reader.cs

示例9: backgroundWorker1_DoWork

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
     this.backgroundWorker1.ReportProgress(0, string.Format("{0}に接続中・・・", this.uri));
     this.client = new WebClient();
     while (this.client.IsBusy)
     {
         Thread.Sleep(100);
         if (this.backgroundWorker1.CancellationPending)
         {
             return;
         }
     }
     Stream stream = this.client.OpenRead(this.uri);
     this.backgroundWorker1.ReportProgress(0, string.Format("{0}に接続完了", this.uri));
     this.backgroundWorker1.ReportProgress(0, string.Format("データを読み込み中", this.uri));
     StreamReader reader = new StreamReader(stream);
     string str = reader.ReadToEnd();
     this.xmltext = str;
     reader.Close();
     this.backgroundWorker1.ReportProgress(0, string.Format("完了", this.uri));
     }
     catch (Exception exception)
     {
     throw new Exception(exception.Message);
     }
 }
开发者ID:pudwinkie,项目名称:neith,代码行数:28,代码来源:UpdateFileForm.cs

示例10: ReadTwineData

    public List<string> ReadTwineData(string path)
    {
        string temp;
        string[] file;

        try
        {
            //create a stream reader
            //get the data in the text file
            //close the stream reader
            StreamReader sr = new StreamReader(path);
            temp = sr.ReadToEnd();
            sr.Close();

            //parse large string by lines into an list
            file = temp.Split("\n"[0]);
            foreach (string s in file)
            {
                twineInfo.Add(s);
            }
            return twineInfo;
        }

        catch (FileNotFoundException e)
        {
            Debug.Log("The process failed: {0}" + e.ToString());
            return null;
        }
    }
开发者ID:ajman1101,项目名称:Remy-The-Flossopher,代码行数:29,代码来源:TwineImporter.cs

示例11: GetSyntaxString

    /// <summary>
    /// Get the syntax string from the wiki
    /// </summary>
    /// <param name="page">The name of the function you wish to look up</param>
    /// <returns>The function syntax string</returns>
    public string GetSyntaxString(string page)
    {
        WebRequest request = WebRequest.Create("http://wiki.multitheftauto.com/wiki/" + page);
        HttpWebResponse response;
        try
        {
            response = (HttpWebResponse)request.GetResponse();
        }
        catch
        {
            return "Error";
        }
        Stream dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string strHTML = reader.ReadToEnd();

        int iStartIndex = strHTML.IndexOf(@"<!-- PLAIN TEXT CODE FOR BOTS |") + (@"<!-- PLAIN TEXT CODE FOR BOTS |").Length;
        int iEndIndex = strHTML.IndexOf(@"|-->");

        if (iEndIndex <= iStartIndex)
            return "Error";

        string strSyntax = strHTML.Substring(iStartIndex, iEndIndex - iStartIndex);

        reader.Close();
        dataStream.Close();
        response.Close();

        return strSyntax;
    }
开发者ID:F420,项目名称:mtasa-blue,代码行数:35,代码来源:ArgStreamer.cs

示例12: GetConfig

    public static void GetConfig(ref string NrIP, ref string NmLastUser, ref string SnPreEtiq, ref string NrTmpAtv)
    {
        if (File.Exists("LogosConfig.txt"))
        {
            StreamReader objReader = new StreamReader("LogosConfig.txt");
            NrIP = objReader.ReadLine();

            if (objReader.EndOfStream == false)
            {
                NmLastUser = objReader.ReadLine();
            }

            if (objReader.EndOfStream == false)
            {
                SnPreEtiq = objReader.ReadLine();
            }

            if (objReader.EndOfStream == false)
            {
                NrTmpAtv = objReader.ReadLine();
            }

            objReader.Close();
        }
    }
开发者ID:wlclimaco,项目名称:washington-sgge-1-0-0,代码行数:25,代码来源:Controller.cs

示例13: Main

 static void Main()
 {
     try
     {
         StreamReader readFile = new StreamReader("..\\..\\text.txt");
         try
         {
             string line = readFile.ReadLine();
             for (int index = 1; line != null ; index ++)
             {
                 if (index % 2 != 0)
                 {
                     Console.WriteLine(line);
                 }
                 line = readFile.ReadLine();
             }
         }
         finally
         {
             readFile.Close();
         }
     }
     catch (Exception exp)
     {
         Console.WriteLine(exp.Message);
     }
 }
开发者ID:KirilToshev,项目名称:Projects,代码行数:27,代码来源:ReadAndPrintFile.cs

示例14: GetIPTCData_1

    public static string GetIPTCData_1(String imageurl)
    {
        string data;
        data = "img=" + imageurl;
        byte[] byteArray = Encoding.UTF8.GetBytes(data);
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8081/www/google/testimgmd5.php");
        httpWebRequest.ContentType = "application/x-www-form-urlencoded";
        httpWebRequest.ContentLength = byteArray.Length;
        httpWebRequest.Method = "POST";
        httpWebRequest.Accept = "*/*";
        httpWebRequest.Headers.Add("Authorization", "Basic reallylongstring");

        //Get the stream that holds request data by calling the GetRequestStream method.
        Stream dataStream = httpWebRequest.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        //Send the request to the server by calling GetResponse. This method returns an object containing the server's response. The returned WebResponse object's type is determined by the scheme of the request's URI
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            string md5content = streamReader.ReadToEnd();
            streamReader.Close();
            return md5content;
        }
    }
开发者ID:sruthiravindra,项目名称:brandyyfiles,代码行数:27,代码来源:activity-listing.aspx.cs

示例15: cargar

	public  void cargar(){



		int numero = 0;
		StreamReader sr = new StreamReader (ruta);

		while (sr.ReadLine()!=null) {

			numero++;

		}
		sr.Close ();
		sr = new StreamReader (ruta);

		 arreglo = new string[numero];
		Debug.Log (arreglo.Length);


		for (int i=0; i<arreglo.Length; i++) {

			String linea=sr.ReadLine();
			arreglo[i]=linea;
		}
		sr.Close ();



	}
开发者ID:JimmyGuarin,项目名称:Inmunology-Game-2.0,代码行数:29,代码来源:prueba.cs


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