Questions tagged [file.readalllines]
88 questions
78
votes
3 answers
What is the difference between File.ReadAllLines() and File.ReadAllText()?
What is the difference between File.ReadAllLines() and File.ReadAllText()?

iTayb
- 12,373
- 24
- 81
- 135
61
votes
3 answers
What is the difference between File.ReadLines() and File.ReadAllLines()?
I have query regarding File.ReadLines() and File.ReadAllLines().what is difference between
them. i have text file where it contains data in row-wise.File.ReadAllLines() return array and using File.ReadLines().ToArray(); will also i can get same…

sp_m
- 2,647
- 8
- 38
- 62
11
votes
0 answers
FileStream was asked to open a device that was not a file
I'm monitoring an FTP folder for orders which I then read into string array for further processing before deleting the file.
On the whole is works but occasionally I get the following exception:
FileStream was asked to open a device that was not a…

MarkBrad
- 171
- 2
- 10
5
votes
1 answer
Is File.ReadAllLines lazy loaded when using with LINQ Where?
I would like to know if the following code is lazy evaluated or will crash in the way I handle possible exception of ReadAllLines(). I know for sure that Where clause is lazy evaluated but I'm not sure when I use it with ReadAllLines().
A possible…

CodeArtist
- 5,534
- 8
- 40
- 65
3
votes
3 answers
File.ReadAllText can't read
My problem is that I want to parse a file and it had to detect a special char ('Â') to do some stuff. I didn't manage to detect it but it worked with normal chars like 'a'.
So I tried to understand where the problem was coming from, and created a…

Sifflex
- 51
- 2
- 7
3
votes
2 answers
Using File.ReadAllLines from embedded text file
I have been applying what I have learned so far in Bob Tabors absolute beginners series and I wrote a small console word game for my daughter that requires me to generate a random 5 letter word.
I was previously using File.ReadAllLines(path) to…

Tater
- 31
- 1
- 2
3
votes
5 answers
Need help in understanding the explanation by Microsoft for File.ReadLines and File.ReadAllLines
According to the explanation by Microsoft for The ReadLines and ReadAllLines methods, When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned. When you use ReadAllLines, you must wait for…

Piush
- 53
- 1
- 7
3
votes
2 answers
Get Line Numbers From File.ReadAllLines() Result
I am reading a text file using File.ReadAllLines(), but I can also use File.ReadLines(). After I read the file, the next step is creating a list from the result. In my list I need to get the line number for each entry/row in the text file. Can…

Big Daddy
- 5,160
- 5
- 46
- 76
2
votes
1 answer
Get Second Instance of Reading a Text File using StartsWith()
I'm reading from a text file to find the Line Index where a certain line starts with my Criteria.
Turns out there are actually two instances of my desired criteria and I want to get the second one.
How would I amend the below code to Skip the first…

craig157
- 355
- 1
- 3
- 18
2
votes
1 answer
Files.readAllLine() not working after FileWriting
hoping you're doing well, this is my first question
I have a trouble:
My goal is to create java files from pieces of code (fields, attributes, constructor)
I tried to do this by altering between reading and writing file.
Reading file to get the…

NASSIM ADRAO
- 145
- 1
- 9
2
votes
1 answer
File.ReadLines returns null char after each other char
I am trying to read all lines from the file, however I am getting some unexpected results, code:
var readLines = File.ReadLines(file);
foreach (var line in readLines)
{
//line = "T\0e\0s\0t\0"
}
File contents:
Test
If I will do…

Vladimirs
- 8,232
- 4
- 43
- 79
2
votes
2 answers
Why does ReadAllLines work in WPF but not in ConsoleApp
I am doing some benchmarking on different ways to read a CSV file and found a "wierd" problem. The problem being that when I use this method in a console application:
var lines = File.ReadAllLines(fileName); // OutOfMemoryException
…

Simon
- 151
- 2
- 10
1
vote
2 answers
Create the file if readalltext can't find it
I'm writing an application in visual studio using c#. I want to check if readalltext finds the file correctly, if not it needs to create the file and put a zero in it. In pseudocode:
if(x=File.ReadAllText("file.txt")==NULL)
{
…

Dillon Wreek
- 53
- 1
- 9
1
vote
1 answer
VB.net Read Specific Lines From a Text File That Start With and Stop Reading When Start With
I'm looking to read lines from a text file that start with certain characters and stop when the line starts with other characters. So in my example I would like to start reading at line AB and stop at line EF however not all lines will contain the…

Nick
- 155
- 4
- 16
1
vote
1 answer
VB.net exporting 2 specific lines to a DataGridView
I'm trying to read all lines of a text file and export only 2 specific lines to a DataGridView. I have most of the code working, however I ran into a problem where the data isn't always on the same line.
I'm using VB.net Here is the code I'm…

Nick
- 155
- 4
- 16