streamreader

Why does this code hang on reaching the first ReadLine from a StreamReader?

风流意气都作罢 提交于 2019-12-04 07:16:38
问题 I was passing a large file in the first arg to SendXMLFile() below but, since it was causing the handheld device to "hang"/"freeze" I temporarily hard-coded a much smaller file (3 KB as opposed to 1121 KB) for testing. The file does indeed exist (in the same folder as the .exe/.dll), as can be seen by this code: // test with smaller file: fileName = "DSD_v6666_3_20140310140737916.xml"; MessageBox.Show("Made it before file.Open"); using (FileStream fileTest = File.Open(fileName, FileMode

Stream Reader Readline detect newline characters

偶尔善良 提交于 2019-12-04 06:02:02
问题 I'm trying to remove any "new line" characters from each line of text in my log file. Below is an example entry that I am reading in with a Stream Reader :- <![LOG[Raising event: [SMS_CodePage(850), SMS_LocaleID(2057)] instance of SoftDistProgramStartedEvent { AdvertisementId = "000216F6"; ClientID = "GUID:B55C2757-CBAE-468E-B54F-46CAF2ECF68F"; CommandLine = "\"C:\\WINNT\\system32\\cscript.exe\" /nologo Shutdown_Desktops_Overnight.vbs"; DateTime = "20130211080211.784000+000"; MachineName =

C# StreamReader, “ReadLine” For Custom Delimiters

不羁岁月 提交于 2019-12-04 00:21:09
What is the best way to have the functionality of the StreamReader.ReadLine() method, but with custom (String) delimiters? I'd like to do something like: String text; while((text = myStreamReader.ReadUntil("my_delim")) != null) { Console.WriteLine(text); } I attempted to make my own using Peek() and StringBuilder , but it's too inefficient. I'm looking for suggestions or possibly an open-source solution. Thanks. Edit I should have clarified this earlier...I have seen this answer , however, I'd prefer not to read the entire file into memory. I figured I would post my own solution. It seems to

Loading a .csv file into dictionary, I keep getting the error “cannot convert from 'string[]' to 'string'”

倖福魔咒の 提交于 2019-12-03 12:22:49
I've used streamreader to read in a .csv file, then i need to split the values and put them into a dictionary. so far i have: namespace WindowsFormsApplication2 { public partial class Form1 : Form { Dictionary<string, string> dict = new Dictionary<string, string>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { using (StreamReader reader = new StreamReader("textwords0.csv")) { string line; while ((line = reader.ReadLine()) != null) { string[] parts = line.Split(','); dict.Add(parts[0], parts[1]); } } } I keep getting the error "cannot convert

check if string exists in a file

孤者浪人 提交于 2019-12-03 07:44:23
I have the following piece of code which opens a text file and reads all the lines in the file and storing it into a string array. Which then checks if the string is present in the array. However the issue I'm facing is that whenever a string is found, it always shows "there is a match" as well as "there is no match". Any idea how to fix this? check this code: using (StreamReader sr = File.OpenText(path)) { string[] lines = File.ReadAllLines(path); for (int x = 0; x < lines.Length - 1; x++) { if (domain == lines[x]) { sr.Close(); MessageBox.Show("there is a match"); } } if (sr != null) { sr

Reading a line from a streamreader without consuming?

北城以北 提交于 2019-12-03 06:44:16
问题 Is there a way to read ahead one line to test if the next line contains specific tag data? I'm dealing with a format that has a start tag but no end tag. I would like to read a line add it to a structure then test the line below to make sure it not a new "node" and if it isn't keep adding if it is close off that struct and make a new one the only solution i can think of is to have two stream readers going at the same time kinda suffling there way along lock step but that seems wastefull (if

How to skip invalid characters in stream in Java/Scala?

孤街浪徒 提交于 2019-12-02 20:35:21
For example I have following code Source.fromFile(new File( path), "UTF-8").getLines() and it throws exception Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:260) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319) I don't care if some lines were not read, but how to skip invalid chars and continue reading lines? Joachim Sauer You can influence the way that the charset decoding handles invalid input by calling CharsetDecoder.onMalformedInput . Usually you won't ever see a

Reading a line from a streamreader without consuming?

▼魔方 西西 提交于 2019-12-02 20:23:23
Is there a way to read ahead one line to test if the next line contains specific tag data? I'm dealing with a format that has a start tag but no end tag. I would like to read a line add it to a structure then test the line below to make sure it not a new "node" and if it isn't keep adding if it is close off that struct and make a new one the only solution i can think of is to have two stream readers going at the same time kinda suffling there way along lock step but that seems wastefull (if it will even work) i need something like peek but peekline The problem is the underlying stream may not

Why does this code hang on reaching the first ReadLine from a StreamReader?

[亡魂溺海] 提交于 2019-12-02 15:16:58
I was passing a large file in the first arg to SendXMLFile() below but, since it was causing the handheld device to "hang"/"freeze" I temporarily hard-coded a much smaller file (3 KB as opposed to 1121 KB) for testing. The file does indeed exist (in the same folder as the .exe/.dll), as can be seen by this code: // test with smaller file: fileName = "DSD_v6666_3_20140310140737916.xml"; MessageBox.Show("Made it before file.Open"); using (FileStream fileTest = File.Open(fileName, FileMode.CreateNew)) { fileTest.Write(info, 0, info.Length); fileTest.Flush(); } if (!File.Exists(fileName)) {

Why am I getting, “Unable to connect to the remote server”?

梦想与她 提交于 2019-12-02 10:09:44
This err msg is the next one I get after resolving “NotSupportedException” as noted here I don't even reach the break point in the server code (set on the first line of the method that should be getting called). This is the relevant server code: [Route("api/PlatypusItems/PostArgsAndXMLFileAsStr")] public async void PostArgsAndXMLFileAsStr([FromBody] string stringifiedXML, string serialNum, string siteNum) { string beginningInvoiceNum = string.Empty; // <= Breakpoint on this line string endingInvoiceNum = string.Empty; XDocument doc = XDocument.Load(await Request.Content.ReadAsStreamAsync()); .