streamreader

Seeking for a line i a text file

烈酒焚心 提交于 2019-12-11 07:56:21
问题 I need some assistance, I am writing a method to read a text file, and if any exception occurs I append a line to the text file. e.g " ** " So what I need to know is how can I check for that specific line of text in the text file without reading every line of the text file, like a peek method or something. Any help would be appreciated. Thanks in advance. 回答1: You can use File.ReadLines in combination with Any: bool isExcFile = System.IO.File.ReadLines(path).Any(l => l == "**"); The ReadLines

Trouble getting contents of resource text file into StreamReader

主宰稳场 提交于 2019-12-11 07:31:52
问题 I'd like to have a GUI that gives the user two options: Read in a key file loaded by the user through openFileDialog. Read in a preloaded key file (user would select one using radioButtons). This would be helpful in that the user would not need to carry around all our key files, but it would still allow flexibility if a new key file needed to be added. My code is currently working for option #1. I use: readFile = new StreamReader(KeyFileFullPath); where KeyFileFullPath is the filepath to the

File encoding when reading a file with StreamReader

有些话、适合烂在心里 提交于 2019-12-11 05:49:45
问题 I am now having an issue where Celsius symbol gets read as C instead of °C. Looks like the encoding the culprit. I tried to do this: using (StreamReader sr = new StreamReader(this._inFilePath,System.Text.Encoding.Unicode ,true)) instead of using (StreamReader sr = new StreamReader(this._inFilePath)) but I am now getting garbage....does the original file encoding have to match the StreamReader encoding? I am using compact framework 2.0. I have found this online, but if use this I have read it

Converting a StreamReader(String) to be compatible with UWP API?

柔情痞子 提交于 2019-12-11 05:22:09
问题 I'm running into a snag utilizing the StreamReader class. On the StreamReader Class documentation page, it states that it supports Universal Windows Platforms (UWPs) under the Version Information header, "Universal Windows Platform - Available since 8". Upon further inspection of its constructors, the StreamReader(Stream) constructors do support UWP apps, however the StreamReader(String) constructors do not support them. I'm currently using the StreamReader(String) constructor with the

Windows Phone 8 choose text file C#

牧云@^-^@ 提交于 2019-12-11 04:27:38
问题 i have a question. If there is a possibility at windows phone 8 at visual studio to create button event to read text file? i know about streamReader and if i declare wchich exacly file i want to read, but if i want to choose from list of files wchich i want to display. i did research on the Internet but i didint find an answer. I know i can use isolatedStorage to read music, video, image but not text files, on the app i created few files with text in it and i want users to have posibility to

How to edit a text file in c# with StreamWriter?

青春壹個敷衍的年華 提交于 2019-12-11 04:03:37
问题 I have a method to edit a word from a text file file and display it on the command prompt. Now I an trying to make a method to edit a word from a text file and write it to a new file. I would also like to mention that I cannot use the File or Regex class since I am not allowed to use it for my assignment. Here is my code for the StreamReader: public void EditorialControl(string fileName, string word, string replacement) { List<string> list = new List<string>(); using (StreamReader reader =

Can I get StreamReader.EndOfStream to return false after the first time I read a file?

こ雲淡風輕ζ 提交于 2019-12-11 03:34:56
问题 ---short version: When I get to the while (!checkReader.EndOfStream) every time after the first, it says EndOfStream = true . ---more detail: A user will upload a file using an Ajax AsyncFileUpload control. I take that file, ensure it's a very specific format of csv that we use and spit it out into a GridView. This all works great the first time through: I get the file, parse it out, and it displays great. But, if I call this same code again anytime during the user's session the StreamReader

StreamReader path changes automatically

淺唱寂寞╮ 提交于 2019-12-11 02:27:13
问题 I have some strange problem (for me). There is an application which is a windows form application "firstapp.exe". There is another application which is windows form application too "launcher.exe". And there is a console application with name "server.exe". Both firstapp and launcher are in the same directory. In that directory there is also a "Config" folder with some other files in it. The code which I use to read one file from config folder in firstapp: StreamReader reader = new StreamReader

How to properly handle blank, null, or empty lines in C#

こ雲淡風輕ζ 提交于 2019-12-11 01:37:19
问题 I have some C# code that is working with a text file, and i can not seem to get it to work properly with blank or null (whitespace) lines. My code: while (!file.EndOfStream) { line = file.ReadLine(); bool isComment = (line[0] == '/') && (line[1] == '/'); bool isPoint = (line[0] == '(') && (line[line.Length - 1] == ')'); bool isWhiteSpace = string.IsNullOrEmpty(line); Debug.Log("Comment: " + isComment + ", Point: " + isPoint + ", WhiteSpace: " + isWhiteSpace + "Value: '" + line + "'"); if (

Read a .csv file in c# efficiently? [closed]

半腔热情 提交于 2019-12-10 23:39:49
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I'm reading huge csv files (about 350K lines by file) using this way: StreamReader readFile = new StreamReader(fi); string line; string[] row; readFile.ReadLine(); while ((line = readFile.ReadLine()) != null) { row = line.Split(';'); x=row[1]; y=row[2]; //More code and assignations here... }