Questions tagged [streamreader]

StreamReader is a C# class designed for character input in a particular encoding, it can be used for reading lines of information from a standard text file. By default, a StreamReader is not thread safe.

Implements a TextReader that reads characters from a byte stream in a particular encoding.

StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. StreamReader can be used for reading lines of information from a standard text file.

StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system. If you get the current character encoding using the CurrentEncoding property, the value is not reliable until after the first Read method, since encoding auto detection is not done until the first call to a Read method.

By default, a StreamReader is not thread safe. See TextReader.Synchronized for a thread-safe wrapper.

Official Microsoft documentation

1931 questions
5
votes
2 answers

Read Oracle BLOB field

I try to read an Oracle BLOB field and show the content i a richTextBox. The examples i find with google are almost the same but still i can't get it to work. I know that the BLOB field contains serialized data. This is what i have so far: (the…
Hansvb
  • 113
  • 1
  • 1
  • 13
5
votes
1 answer

How to read StreamReader text line by line

I have a text file hosted and this file have a organized string like this: First line Second line Third line Fourth line Sixth line Seventh line .................... I'm getting all content from this file with following function: private…
user5404910
5
votes
2 answers

C# Application Relative Paths

I just started learning C# and it looks like when you are writing an output file or reading an input file, you need to provide the absolute path such as follows: string[] words = { "Hello", "World", "to", "a", "file", "test" }; using…
Jack Frye
  • 583
  • 1
  • 7
  • 28
5
votes
4 answers

C# StreamWriter and StreamReader memory managment problem, why won't memory used deallocate?

So I'm using a StreamReader that uses a MemoryStream to write to a StreamWriter and inside of this application but the memory usage increases by 300mb (From one of the larger inputs) and does not deallocate after Im done using it: StreamWriter log =…
Sam F
  • 621
  • 1
  • 8
  • 16
5
votes
0 answers

Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read

Cannot get program to read the file, not sure what I'm doing wrong here, any advice is welcomed. Trying to do a project for an address book and the file contains all the people's names and addresses and phone numbers. public Form1() …
Alan Mederos
  • 61
  • 1
  • 4
5
votes
1 answer

Check for fixed-length marker at end of file

I have an application that I've been tasked with cleaning up after. The application itself is relatively simple - it runs a SQL query, consumes a web service, and spews the results to a log file. My job is to archive the files to our NAS after the…
monkeyninja
  • 301
  • 4
  • 7
5
votes
1 answer

How to string multiple TextReaders together?

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…
Ken
  • 396
  • 2
  • 4
5
votes
2 answers

Why is my Stream not Readable?

This is a sequel to my question here about trimming the fat off a log file. I have this code: private readonly FileStream _fileStream; private readonly StreamWriter _streamWriter; . . . const int MAX_LINES_DESIRED = 1000; string uriPath =…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
5
votes
1 answer

Override Render of a page / StreamReader size limit?

So, I'm playing around with getting the HTML out of a standard ASP.Net Page. I've overridden the Render method, as so: protected override void Render(HtmlTextWriter writer) { MemoryStream memoryStream = new MemoryStream(); try { …
Matt Grande
  • 11,964
  • 6
  • 62
  • 89
5
votes
3 answers

Get length of Streamreader

How can I get the length of a StreamReader, as I know nothing will be written to it anymore. I thought that maybe I could pass all the data to a MemoryStream, which has a method called Length, but I got stuck on how to append a byte[] to a…
Bruno Klein
  • 3,217
  • 5
  • 29
  • 39
5
votes
4 answers

Check if a StreamReader can read another line

I need to check if a line contains a string before I read it, I want to do this using a while loop something like this while(reader.ReadLine() != null) { array[i] = reader.ReadLine(); } This obviously doesen't work, so how can I…
jlodenius
  • 829
  • 2
  • 13
  • 24
5
votes
1 answer

Read in a file using a regular expression?

This is tangentially related to an earlier question of mine. Essentially, the solution in that question worked great, but now I need to adapt it to work in a much larger analysis application. Simply using StreamReader.ReadToEnd() is not acceptable,…
tmesser
  • 7,558
  • 2
  • 26
  • 38
4
votes
2 answers

C# Read only first line, using StreamReader of a zipped text file

I am trying to read only the first line of a zipped csv file. I used below code but get the error "The magic number in GZIP header is not correct". Obviously it has to do with the fact that GZIP and ZIP are not identical formats but I do not seem to…
Matt
  • 7,004
  • 11
  • 71
  • 117
4
votes
3 answers

Using StreamReader and StreamWriter to Modify Files

I am trying to use StreamReader and StreamWriter to Open a text file (fixed width) and to modify a few specific columns of data. I have dates with the following format that are going to be converted to packed COMP-3 fields.…
buzzzzjay
  • 1,140
  • 6
  • 27
  • 54
4
votes
2 answers

Consume a StreamReader stream .NET from a web request as it streams?

I'm experimenting with the Twitter streaming api, and am trying to open a stream for a user to consume events as they happen. I'm using a standard set of classes for making REST api calls to twitter. When using…
wakurth
  • 1,644
  • 1
  • 23
  • 39