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

Value was either too large or too small for an Int32. Reading and parsing textfile

I have been unable to apply any solutions to this issue. The exception happens to this line here: currentMap[row, col] = Int32.Parse(s); What I am wanting to do is pass this method a specific file storing rows of numbers like…
user3622946
  • 3
  • 1
  • 3
0
votes
1 answer

Getting Text from Div C# StreamReader

I'm trying to get a specific div from a textfile filled with div's. I'm using streamreader to get into the file, but I don't know how to get the complete div. After getting the div I'm gonna turn each line into a string, which will be added to a…
Freerk92
  • 55
  • 1
  • 9
0
votes
7 answers

Why is this StreamReader only reading one line?

The following piece of code should read each line of the file and operate on it. However, it only reads the first line. Without the for loop it reads the whole file. I honestly have no idea why it's not reading the whole thing. StreamReader sr = new…
tsvallender
  • 2,615
  • 6
  • 32
  • 42
0
votes
1 answer

StreamReader storing empty lines in list if string contains special characters

The textfile contains hundreds of lines like this and almost all of them are stored in the list. But the lines containing characters such as '-', '&' or dots ('.') are added to the list as empty lines. Out of the lines below: the 1st, 2nd, 7th, 8th,…
Freerk92
  • 55
  • 1
  • 9
0
votes
0 answers

Stream Write between two HTML Tags

If this example I am first iterating through a file directory to get all files that have not been renamed yet, I am doing this by identifying the ones with the current year on it (because it is produced with a time-stamp) Once that is complete it…
user1902540
  • 111
  • 2
  • 12
0
votes
2 answers

c# loading text from textfile into multiple textBoxes at random

I have a textfile called answers.txt. In this textfile I have stated a few answers like this: answer1 | answer2 | answer3 |... Now to read these answers I made a class called answeres and it contains this code: public String getAnswer(int…
user3644837
  • 335
  • 2
  • 3
  • 8
0
votes
1 answer

Starting project in same solution with buttonClickEvent/Closing current c#

What i want to achieve is this: I have a solution with 3 projects inside. I've added these projects to the explorer folder, solution explorer and made a reference from projectA to projectB & projectC. Now what I want is this, when I click a button…
user3644837
  • 335
  • 2
  • 3
  • 8
0
votes
1 answer

File.OpenText() throws a DirectoryNotFoundException on Windows Phone 8

I am trying to read .csv file on Windows Phone 8. And I am writing below code. This similar code runs on C#. But when I click to run I was getting error. PivotPage.xaml.cs: List inputs = new List(); List outputs = new…
Osman Villi
  • 346
  • 2
  • 24
0
votes
0 answers

.NET: Read a Text file wihtout locking it

I need to read a text file while another application is writing to it. In this scenario I've programmed: Dim _fs_ As FileStream = File.Open("c:\log.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite) Dim _sr_ As New StreamReader(_fs_) What I…
user1737538
  • 497
  • 2
  • 7
  • 16
0
votes
0 answers

C# - my ReadLine() gives me a null value when I should get a string

Solved - Accidentally wiped the actual file of data but the ide doesn't update that file unless you reopen it so I thought the data was still in there. I'm working on a project in C# that reads in a fake inventory and then transactions to go with…
0
votes
3 answers

Apply a calculation on all lines from a file

I'm stuck on a problem, I can not execute my calculation on all lines of my text file. The calculation only applies to the first line. I want to see my result in richTextBox2. Here is my code : using (StreamReader sr1 = new…
0
votes
1 answer

C# Import data from text file to text boxes

I just want to say that I only joined stackoverflow a few weeks ago and everyone has been very helpful, thank you. I am down to my last two homework assignments for the semester. What I am trying to do right now is import the data I save to a text…
user3530547
  • 41
  • 6
  • 13
0
votes
2 answers

How to write response of streamReader into textfile in c#

I have a socket program in c#.I want to save the response of the server into textfile.Here is the code that i am using for it.. var streamReader = new StreamReader(client.GetStream()); var serverResponse = streamReader.ReadLine(); How to save this…
0
votes
5 answers

Reading individual words into an array using streamreader C#

I am trying to get a list of words (below) to be put into an array. I want each word to be in it's own index. Here is my code that I have so far. string badWordsFilePath = openFileDialog2.FileName.ToString(); StreamReader sr = new…
user2363217
  • 695
  • 1
  • 7
  • 15
0
votes
2 answers

loop - reading text after a certain string up until a certain string

start=AKS-RHzlSXSftLGYdBNk.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1& For every instance of the word 'start' I need to be able to get the text after the first full stop, right up until the & symbol. E.g. 'eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1'. There will be…
Ash King
  • 229
  • 5
  • 20
1 2 3
99
100