streamreader

Unable to read data from the transport connection: The connection was closed error in console application

给你一囗甜甜゛ 提交于 2019-11-30 18:18:18
I have this code in console application and it runs in a loop try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search); request.Headers.Add("Accept-Language", "de-DE"); request.Method = "GET"; request.Accept = "text/html"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { string html = reader.ReadToEnd(); FindForMatch(html, url); } } } catch (Exception ex) { throw new Exception(ex.Message); } after few loops it gives Unable to read data from the transport

Reading large file in chunks c#

扶醉桌前 提交于 2019-11-30 09:13:07
I want to read very large file (4GBish) chunk by chunk. I am currently trying to use a StreamReader and the Read() read method. The syntax is: sr.Read(char[] buffer, int index, int count) Because the index is an int it will overflow in my case. What should i use instead? The index is the starting index of buffer not the index of file pointer, usually it would be zero. On each Read call you will read characters equal to the count parameter of Read method. You would not read all the file at once rather read in chunks and use that chunk. The index of buffer at which to begin writing, reference .

StreamReader complains that file does not exist, but it does

北城以北 提交于 2019-11-30 08:47:59
I have an application that is localized for use across Europe. I have a menu option that loads a file from disk. This operation works fine on my dev machine but does not work on the virtual machine I use to test other operating systems _ e.g French, Spanish etc. A FileNotFoundException is generated when the StreamReader tries to open the file. It says "'Could not find the file C:\Program Files\MyCompany\MyTool\bin\Files\debug.txt'" Thing is, the file does exist, at the correct location and with the correct filename. The directory names on the target (French) operating system are the same as

What is the purpose of StreamReader when Stream.Read() exists?

做~自己de王妃 提交于 2019-11-30 07:27:21
问题 This has been bugging me. I know Stream is an abstract class and therefore can't be instantiated but it has classes that are derived from it. Why is there a StreamReader class and a Stream.Read() method (and vice verse for StreamWriter and Stream.Write() )? You can write to a text file using 3 million different methods and it's rather frustrating trying to get my head around all of these different types and methods in the System.IO namespace. I found questions and answers regarding the

Read text file from C# Resources

跟風遠走 提交于 2019-11-30 07:05:57
问题 I need to read a file from my resources and add it to a list. my code: private void Form1_Load(object sender, EventArgs e) { using (StreamReader r = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("myProg.myText.txt"))) { //The Only Options Here Are BaseStream & CurrentEncoding } } Ive searched for this and only have gotten answers like "Assembly.GetExecutingAssembly...." but my program doesnt have the option of Assembly.? 回答1: Try something like this : string

Is StreamReader.Readline() really the fastest method to count lines in a file?

巧了我就是萌 提交于 2019-11-30 06:51:53
While looking around for a while I found quite a few discussions on how to figure out the number of lines in a file. For example these three: c# how do I count lines in a textfile Determine the number of lines within a text file How to count lines fast? So, I went ahead and ended up using what seems to be the most efficient (at least memory-wise?) method that I could find: private static int countFileLines(string filePath) { using (StreamReader r = new StreamReader(filePath)) { int i = 0; while (r.ReadLine() != null) { i++; } return i; } } But this takes forever when the lines themselves from

Need to pick up line terminators with StreamReader.ReadLine()

跟風遠走 提交于 2019-11-30 03:25:15
问题 I wrote a C# program to read an Excel .xls/.xlsx file and output to CSV and Unicode text. I wrote a separate program to remove blank records. This is accomplished by reading each line with StreamReader.ReadLine() , and then going character by character through the string and not writing the line to output if it contains all commas (for the CSV) or all tabs (for the Unicode text). The problem occurs when the Excel file contains embedded newlines (\x0A) inside the cells. I changed my XLS to CSV

Unable to read data from the transport connection: The connection was closed error in console application

て烟熏妆下的殇ゞ 提交于 2019-11-30 03:03:23
问题 I have this code in console application and it runs in a loop try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search); request.Headers.Add("Accept-Language", "de-DE"); request.Method = "GET"; request.Accept = "text/html"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { string html = reader.ReadToEnd(); FindForMatch(html, url); } } } catch (Exception ex) {

How do I convert StreamReader to a string?

戏子无情 提交于 2019-11-29 16:43:45
问题 I altered my code so I could open a file as read only. Now I am having trouble using File.WriteAllText because my FileStream and StreamReader are not converted to a string. This is my code: static void Main(string[] args) { string inputPath = @"C:\Documents and Settings\All Users\Application Data\" + @"Microsoft\Windows NT\MSFax\ActivityLog\OutboxLOG.txt"; string outputPath = @"C:\FAXLOG\OutboxLOG.txt"; var fs = new FileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite |

How to string multiple TextReaders together?

谁说胖子不能爱 提交于 2019-11-29 14:08:38
I have 3 TextReaders -- a combination of StreamReaders and StringReaders. Conceptually, the concatenation of them is a single text document. I want to call a method (not under my control) that takes a single TextReader. Is there any built-in or easy way to make a concatenating TextReader from multiple TextReaders? (I could write my own TextReader subclass, but it looks like a fair amount of work. In that case, I'd just write them all out to a temp file and then open it with a single StreamReader.) Is there an easy solution to this that I'm missing? I just threw this together, so it's not super