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
2 answers

add url from text file to string array (Android)

i am working on image gallery app in which i am loading images from internet so i have added many image URLs in a text file now i want to add these URLs from text file to string array. i don't know how to add text from file to my code (public…
0
votes
2 answers

Ignore certain lines in a text file (C# Streamreader)

I'm trying to work out a way of removing records from a program I'm writing. I have a text file with all the customer data spread over a set of lines and I read in these lines one at a time and store them in a List When writing I simply append to…
0
votes
0 answers

Streamreader editing too much content

I am creating a quiz but one of the options the quiz must have is the option to edit questions. The program finds the question by the question number and then asks the user which part of the question does the user want to edit between the question…
COYG
  • 1,538
  • 1
  • 16
  • 31
0
votes
2 answers

Replace List with words from a file, keep the order

public static List items = new List() { "a","b","c","d","e" }; I am trying to change each of those from loading a file and replacing with their current inventory. if (File.Exists("darColItems.txt") == true) { char c = ','; …
0
votes
2 answers

Why is the while loop or if statement not behaving correctly? c#

My program is a quiz. The questions start easy at level one questions when the user gets a question correct they go to a level two question, if they get this question correct they go to a level 3 question and so on. This is working correctly (except…
COYG
  • 1,538
  • 1
  • 16
  • 31
0
votes
2 answers

Using split() method without text qualifier

I'm trying to get some field value from a text file using a streamReader. To read my custom value, I'm using split() method. My separator is a colon ':' and my text format looks like: Title: Mytitle Manager: Him Thema: Free ..... Main Idea:…
Thim
  • 1
  • 2
0
votes
1 answer

How to display all the files & folders from ftp in tree view using c#?

I am doing windows application, in that application I need to display the all the files and folder from FTP in tree view. I did some of the sample code which is, private void button1_Click(object sender, EventArgs e) { var root =…
0
votes
1 answer

StreamReader.Peek for Multiline Textbox

I coded the StreamReader.Peek method like this Dim sr As StreamReader = New StreamReader(Textbox1.Text) Dim line As String = "" Do While sr.Peek() >= 0 .... But it came up with an exception that it could not find the file "text in textbox" I…
Phexion
  • 59
  • 1
  • 2
  • 8
0
votes
1 answer

can we create a clone object of streamreader class in c#?

How can I create a clone object of streamreader, when i do Serializing on streamreader object, program give me exception : Unhandled Exception: System.Runtime.Serialization.SerializationException: Type ' System.IO.FileStream' in Assembly…
Rohit
  • 52
  • 6
0
votes
1 answer

StreamReader preprocess

I'm using csvHelper for reading txt file where columns can have names like this "column1 ". Of course I don't want to put such ugly string in my ColumnAttribute [ColumnInfo(typeof(string), "column1") public string Column1{get;set;} That is…
0
votes
0 answers

Post FORM by C# and wait javascript has been executed

I am submitting a aspx with my C# code behind which works good, however I get the html direct back as I do not display this in a browser. This is my C# code: string getUrl = "https://www.facebook.com/login.php?login_attempt=1"; string email =…
Jaap Terlouw
  • 125
  • 1
  • 15
0
votes
0 answers

StreamReader cannot read files with "#" in their name

I'm using this code to read files from ftp server: static List GetDirectory(String DirectoryName) { try { var ConnectionString = String.Format("{0}/{1}", Connection.GetFTPConfig.FTPSourceAddress,…
Soheila Hg
  • 569
  • 2
  • 7
  • 25
0
votes
2 answers

Getting streamreader to read specific line in text file, then write to console c#

I have a struct that holds 4 variable types, the data of this struct is held in a text file. The struct is made up of question number, question level, question, and question answer. I am trying to print only the question to the console window but…
COYG
  • 1,538
  • 1
  • 16
  • 31
0
votes
1 answer

Deleting lines from text file

I'm making a multiple questions quiz on the console application. What I am trying to complete right now is the updating/deleting of questions. I would really appreciate any help and also note that I'm new so if I have missed anything please let me…
Ryan
  • 1
  • 3
0
votes
1 answer

Why is streamreader only picking up first entry? c#

I am using the stream reader feature to search for a record in a text file then display that record on the console window. It is searching the text file by a question number (1-50). The only number it works with is question 1. It won't display any…
COYG
  • 1,538
  • 1
  • 16
  • 31
1 2 3
99
100