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
0
votes
1 answer

Encoding problems using StreamReader and WebResponse

I'm trying to read an XML stream using the WorldBank API. The URL in question is http://api.worldbank.org/country?per_page=100 now in my web browser this runs fine and returns an XML document. However, this will not play nicely in FSI. The stream…
Overly Excessive
  • 2,095
  • 16
  • 31
0
votes
2 answers

how to read two text file line by line in vb.net simultaneously

HELP! i want to read two text file at the same time, i could read a text file line by line but when i added 1 text file to read at the same time it only read the first line and nothing more.. for example: in name.txt it has and in age.txt it has i…
tris
  • 39
  • 1
  • 10
0
votes
2 answers

Find a line containing a certain string in a file

Trying to linear search a file to find a line that starts with a username (and a "," as it makes sure it is the whole username) in a file formatted as ",,," for each line. I'm not sure how to do this so any help is appreciated. Dim lineCorrect…
RedLaser
  • 680
  • 1
  • 8
  • 20
0
votes
1 answer

C# WebClient StreamReader string replace not working

I want to read the response from the URI and modify it by replacing all S's to X's and to return that string back to client. Below is my code, but replace is not working. I downloaded the "response" string to check and there are lots of S…
0
votes
1 answer

How to remove all columns and associated contents after the column name: LAYER in text file

I am trying to remove all the columns after the column name "LAYER" My input text files have a more than 10 columns which are tab delimited Designator MAX PN Footprint Center-X(mm) Center-Y(mm) Layer Fitted Orentation Design …
user4318274
0
votes
1 answer

Using returned XML from an authorised HTTP request in vb.NET

How can I use the returned XML from the reader in a xmltextreader? ' Create the web request request = DirectCast(WebRequest.Create("https://mobilevikings.com/api/1.0/rest/mobilevikings/sim_balance.xml"), HttpWebRequest) …
Nathan
  • 3
  • 2
0
votes
2 answers

Read and empty the file that is being used by another process

I have looked at many posts with the similar title and their suggested answers. But they haven't solved my problem. Examples are this, this and this. I have a text file that is always locked by a Windows Service (it's a logger basically). What I…
disasterkid
  • 6,948
  • 25
  • 94
  • 179
0
votes
2 answers

How to read integers from a text file to array

So this is what I would like to do. I am kind of all over the place with this but I hope you can bear with me. This is a very new concept to me. 1) In my program I wish create an array of 50 integers to hold the data that comes from the file. My…
0
votes
2 answers

C# read file line into List and use as parameters

I'm not quite sure how to do this, but I am trying to read a .CSV file line-by-line storing each independent line into a List<>. Then loop through the list and use each item (row) as a signature for a new instance of my Employee class.…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
0
votes
1 answer

Setting File read pointer at the beginning

Consider the following code below in which for each entry in key.txt I add it to each line in plain.txt and write it to the output.txt. Dim srKeyFile As New StreamReader("D:\Test\key.txt") Dim srOutFile As New…
Naseer
  • 4,041
  • 9
  • 36
  • 72
0
votes
2 answers

StreamWriter is appending BOM character 65279 to end of file

I have a StreamWriter open to my file during the same time that I read from it, which seems to be causing issues (this is a smaller snippet of a larger set of code, just shown to illustrate my issue): static void Main(string[] args) { for (int i…
Alexandru
  • 12,264
  • 17
  • 113
  • 208
0
votes
1 answer

vb.net - How to dissect a delimited string, and then put it into an array to be used for a DGV and calculations

I am currently working on a project in vb.net that involves inputting lines of delimited information from a txt file, then displaying it on a dataviewgrid, AND calculating percentage change between two of the values. How can I input all of this data…
Sean71596
  • 1
  • 1
0
votes
0 answers

C# client and java server interaction

Hello all I hava a big problem with my client-server interaction, when I send a data from client to server it's work but when I send a data from server to my C# client the data are not recieved. my code: server: public void ReceiveData(Socket…
Isador
  • 41
  • 6
0
votes
3 answers

Read multiple lines with StreamReader with StreamReader.Peek

Let's say I have the following file format (Key value pairs): Objec1tKey: Object1Value Object2Key: Object2Value Object3Key: Object3Value Object4Key: Object4Value1 Object4Value2 Object4Value3 Object5Key: Object5Value Object6Key: Object6Value I'm…
Ozkan
  • 3,880
  • 9
  • 47
  • 78
0
votes
0 answers

text file not updated after write c# Windows Phone 8

I'm trying to write string data into a text file in a Windows Phone 8 app but the text file just would not be updated. I'm writing with the codes below public void update_file(Contact_List[] list) //Write to file { using (FileStream fs =…