本文整理汇总了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));
}
示例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();
}
}
示例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();
}
}
示例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()) ;
}
}
示例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();
}
}
}
示例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();
}
示例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);
}
示例8: Read
public static string Read(string path)
{
var reader = new StreamReader(path);
var s = reader.ReadToEnd();
reader.Close();
return s;
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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;
}
}
示例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 ();
}