streamreader

In C#, How can I copy a file with arbitrary encoding, reading line by line, without adding or deleting a newline

百般思念 提交于 2019-12-24 11:53:34
问题 I need to be able to take a text file with unknown encoding (e.g., UTF-8, UTF-16, ...) and copy it line by line, making specific changes as I go. In this example, I am changing the encoding, however there are other uses for this kind of processing. What I can't figure out is how to determine if the last line has a newline! Some programs care about the difference between a file with these records: Rec1<newline> Rec2<newline> And a file with these: Rec1<newline> Rec2 How can I tell the

Closing Stream Read and Stream Writer when the form exits

喜夏-厌秋 提交于 2019-12-24 10:58:04
问题 Hey guys, having a bit of trouble here. So I have a load button that loads the file, and a save button the saves the file. I also have a exit button that closes the program. What I need help with is when I close the program, I wont to check whether there are any StreamReader or StreamWriter things that have not been closed. Heres what I have so far: At the top, i declear these guys bool isDirtyBoolean = false; string moreData = ""; My load button looks like this private void

Reading from a HttpResponseStream fails

拥有回忆 提交于 2019-12-24 10:52:36
问题 I'm running into an issue where reading from a HttpResponseStream fails because the StreamReader that I'm wrapping around in reads faster that the Response Stream gets the actual response. I'm retrieving a reasonably small sized file (around 60k) but the Parser which processes the response into an actual object fails because it hits an unexpected character (Code 65535) which from experience I know to be the character produced when you read from a StreamReader and there are no further

How to read huge CSV file with 29 million rows of data using .net

与世无争的帅哥 提交于 2019-12-24 09:58:38
问题 I have a huge .csv file, to be specific a .TAB file with 29 million rows and the file size is around 600 MB. I would need to read this into an IEnumerable collection. I have tried CsvHelper , GenericParser , and few other solutions but always ending up with an Out of Memory exception Please suggest a way to do this I have tried var deliveryPoints = new List<Point>(); using (TextReader csvreader1 = File.OpenText(@"C:\testfile\Prod\PCDP1705.TAB")) //StreamReader csvreader1 = new StreamReader(@

Is there a maximum line-length in a textfile without a linebreak?

北战南征 提交于 2019-12-24 07:38:38
问题 Trying to use StreamReader or similar from C# to read and write VERY LONG lines without the linebreak. As I understand it, linebreak is still just 2 bytes (CR+LF) in a long bytearray called a file. At least thats how I am used to it in C/C++... Is this the same for C# and .net or is there some maximum length for lines without a linebreak? 回答1: There are no specific limitations in .NET, but different ways of viewing long lines may give you problems, mostly related to performance. Try to open

Getting MalformedChunkCodingException while reading JSON data

左心房为你撑大大i 提交于 2019-12-24 01:24:48
问题 I have getting this exception while parsing JSON data : org.apache.http.MalformedChunkCodingException: Chunked stream ended unexpectedly at org.apache.http.impl.io.ChunkedInputStream.getChunkSize can any one suggest me what to do ...I am reading stream As : HttpPost request = new HttpPost(url); StringBuilder sb=new StringBuilder(); request.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); request.setHeader("Accept", "application/json"); HttpResponse response

SSRS Decrypting database column throws error “Value cannot be null. Parameter name: inputBuffer”

北城余情 提交于 2019-12-24 01:17:05
问题 We have a database field that is encrypted in a C# MVC app using Entity Framework. That part works fine for encrypting and decrypting. We need to show this data decrypted in an SSRS report. I've taken the Decrypt method and converted it to VB.Net and placed in the code behind of the report. The error occurs when calling the StreamReader 's ReadToEnd method. We've found some references online about there being an issue trying to close a stream that's already closed. This stream is only being

Read HTTPWebReponse using GetResponseStream readToEnd return strange characters

佐手、 提交于 2019-12-23 15:44:20
问题 we are reading response from HttpWebResponse and the response itself is quite normal, we think. But when we try to read the string representation of that, we only receive strange characters instead of json formatted normal chars. Can anyone please tell us what is wrong here? Any question or help is welcomed, if more informations are needed, please comment. Thanks 回答1: The response content encoding header is gzip indicating the content has been compressed by the server. Set request

ASP.NET MVC: Can an MSI file be returned via a FileContentResult without breaking the install package?

孤者浪人 提交于 2019-12-23 11:59:17
问题 I'm using this code to return a FileContentResult with an MSI file for the user to download in my ASP.NET MVC controller: using (StreamReader reader = new StreamReader(@"c:\WixTest.msi")) { Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd()); return File(bytes, "text/plain", "download.msi"); } I can download the file, but when I try to run the installer I get an error message saying: This installation package could not be opened. Contact the application vendor to verify that this is a

Java-Sockets: InputStream.read() vs BufferedReader.read()

人走茶凉 提交于 2019-12-23 11:59:13
问题 I'm reading from a Socket's InputStream. Because I'm parsing the incoming data on the fly, I'm required to read character by character. Does BufferedReader.read() the same thing as InputStream.read() does ? (assuming that BufferedReader has been constructed with the InputStream as base) Is it more efficient to use InputStream.read() when reading each character separately? Or is there any better way? 回答1: BufferedReader will read multiple characters from an underlying Reader. An InputStream is