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

HTTPWebResponse and StreamReader need twice the time

Making the request with ajax, takes 13 seconds on Internet Explorer var start = new Date().getTime(); var xmlRequest = ""; //XML REQUEST var xmlHttp=null try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new…
Elton Santana
  • 950
  • 3
  • 11
  • 22
0
votes
1 answer

Writing to MemoryStream from BinaryReader

i am having an issue when trying to read saved List from binary file back to a List. the file is encrypted, without encryption i had no problem. writing method: private void WriteEncodedFile(FileStream fileStream, MemoryStream memoryStream) { …
0
votes
2 answers

Using a StreamWriter and StreamReader results in error "Stream not readable"

I am trying to save data to a csv file but want to ensure that the data that I am about to save isn't already pressent in the csv file. Because of this I want to read the file first and then save the data. FileStream writer = new FileStream(path,…
BigMan
  • 83
  • 2
  • 12
0
votes
1 answer

How to I make a StreamReader skip a line when I already have another delimiter?

Okey. So I'm making this simple script that spawns blocks from an Array, almost like a tilebased 2d game. But it is not preforming as I want it to, I know why, but I have'nt found any solution. Please help me out if you can :) So here I run the…
0
votes
1 answer

Reading text only in parentheses c#

I am writing an application that will read a text file and only read text inside parentheses that starts with a T#. I am having a hard time doing all this. I can read the first line in parentheses with string fname = dialog.FileName; // selected…
0
votes
1 answer

stream reader not moving to the next record in the file

I'm developing a quiz with 50 questions, the quiz needs 5 question levels with the user moving up and down them based on correct and incorrect answers. For my level 1 questions i have set up a text file containing 10 questions in this…
craigy g
  • 9
  • 1
0
votes
1 answer

FtpWebRequest UploadFile From String Data (not a file)

There are many samples of c# code showing how to upload a file when a stream is being read from file on disk. So I think I need to do a new Stream, but I do not understand what this means: StreamReader sourceStream = new StreamReader(Stream stream)
0
votes
1 answer

Usage of StreamReader in C#

I want to read a file data.json and convert it to a string. My code is this one: String json = null; using (StreamReader sr = new StreamReader("data.json")) { json = sr.ReadToEnd(); } but Visual Studio tells me that StreamReader does not…
nix86
  • 2,837
  • 11
  • 36
  • 69
0
votes
3 answers

How to read and write a list object into a file

I had written a list object to a file like this private List _cacheFileList=new List(4); _cacheFileList.Add("Something"); using (StreamWriter file = new StreamWriter(@"cache.bin")) { …
Sowvik Roy
  • 885
  • 2
  • 11
  • 25
0
votes
0 answers

rolling back wrong encoded string

I have a really bad problem. I have a lot of records in database which are in Persian language. For some reasons, I load them, make some changes to them (by HtmlAgilityPack), and then save them back to db. But all strings gone to ?????????????…
amiry jd
  • 27,021
  • 30
  • 116
  • 215
0
votes
0 answers

Input from text file to list box in VB 2012

I'm trying to get input from a text file to load into a listbox so that I can do more calculations. I have the math done and all the coding; but when I execute the program it simply won't display the items from the text file into the main list box…
Shawn
  • 9
  • 2
  • 6
0
votes
1 answer

Foreach (line.contains("id") in reader.readline())

recently i started to make a user-interface manager based on .nui file(s), they look like this : begin genwnd id = addinformation_creature; spr = ui_frame.spr; rect = 0,0,220,319; style = KSTYLE_NOCLOSE | KSTYLE_NOMINIMIZE | KSTYLE_NORESIZE |…
Cotemp
  • 55
  • 1
  • 4
0
votes
3 answers

StreamReader function cannot understand string variable

I'm using VB .Net for Windows Phone 8. I'm trying to get first line from txt file. Txt file is located in Web. Dim path As String path="http://web.com/text.txt" Using TXT As New StreamReader(path) TextBox1.Text = TXT.ReadLine() End Using And I…
Artur Tychina
  • 105
  • 2
  • 8
0
votes
2 answers

C# DataGridView: How to change a single cell value

I have 2 forms. First form contains the datagridview and on the second form the users can change a single value in the datagridview in first form. The problem is if the user changes a value, the same value in other cells are changed too. Ex)…
user2349228
  • 19
  • 1
  • 6
0
votes
2 answers

Need help to read text from text file to ArrayList (Android)

i am working on an image gallery app in which i am loading images from URL so i have saved some image URLs in a text file and i am trying to read URLs from text file to ArrayList but i am not able to load images in my app. i tried this: but…