I'm doing:
Dim Contents() As String = System.IO.File. ReadAllLines("C :\MyFile.txt") with
upwards of 100,000 lines.
This is a brilliantly simple and fast way of creating an array from a text
file. However, it seems to be restricted as there are no overloads for
FileSharing (I have another application which might add to the file whilst
it is being read). The only alternative I have found is using a large amount
of looping with StreamReader which takes forever.
Is there another way?
-Jerry 4 6313
On Sep 22, 10:02*am, "Jerry Spence1" <1...@dfgh.comw rote:
I'm doing:
Dim Contents() As String = System.IO.File. ReadAllLines("C :\MyFile.txt")w ith
upwards of 100,000 lines.
This is a brilliantly simple and fast way of creating an array from a text
file. However, it seems to be restricted as there are no overloads for
FileSharing (I have another application which might add to the file whilst
it is being read). The only alternative I have found is using a large amount
of looping with StreamReader which takes forever.
Is there another way?
-Jerry
Look at this thread to consider shared access explicty: http://groups.google.com/group/micro...190e9b741688bb
HTH,
Onur Güzel
On Sep 22, 2:02 am, "Jerry Spence1" <1...@dfgh.comw rote:
I'm doing:
Dim Contents() As String = System.IO.File. ReadAllLines("C :\MyFile.txt") with
upwards of 100,000 lines.
This is a brilliantly simple and fast way of creating an array from a text
file. However, it seems to be restricted as there are no overloads for
FileSharing (I have another application which might add to the file whilst
it is being read). The only alternative I have found is using a large amount
of looping with StreamReader which takes forever.
Is there another way?
-Jerry
I'm not sure why you think a StreamReader would any slower than
calling ReadAllLines. Here is the code for the ReadAllLines method:
Public Shared Function ReadAllLines(By Val path As String, ByVal
encoding As Encoding) As String()
Dim list As New ArrayList
Using reader As StreamReader = New StreamReader(pa th, encoding)
Dim str As String
Do While (Not str = reader.ReadLine Is Nothing)
list.Add(str)
Loop
End Using
Return DirectCast(list .ToArray(GetTyp e(String)), String())
End Function
As you can see, it is using a StreamReader.
Chris
"Chris Dunaway" <du******@gmail .comwrote in message
news:60******** *************** ***********@m73 g2000hsh.google groups.com...
On Sep 22, 2:02 am, "Jerry Spence1" <1...@dfgh.comw rote:
>I'm doing:
Dim Contents() As String = System.IO.File. ReadAllLines("C :\MyFile.txt") with upwards of 100,000 lines. This is a brilliantly simple and fast way of creating an array from a text file. However, it seems to be restricted as there are no overloads for FileSharing (I have another application which might add to the file whilst it is being read). The only alternative I have found is using a large amount of looping with StreamReader which takes forever.
Is there another way?
-Jerry
I'm not sure why you think a StreamReader would any slower than
calling ReadAllLines. Here is the code for the ReadAllLines method:
Public Shared Function ReadAllLines(By Val path As String, ByVal
encoding As Encoding) As String()
Dim list As New ArrayList
Using reader As StreamReader = New StreamReader(pa th, encoding)
Dim str As String
Do While (Not str = reader.ReadLine Is Nothing)
list.Add(str)
Loop
End Using
Return DirectCast(list .ToArray(GetTyp e(String)), String())
End Function
As you can see, it is using a StreamReader.
Chris
Thanks Chris. I believed it would be slower because you are looping round
the Do While loop, and the System.File.Rea dAllLines happens in one line - no
looping. However, I've just experimented with 1million lines and there
doesn't seem to be that much difference, so I guess this is what
System.File.Rea dAllLines does behind the scenes. However, I can't find a way
of setting the FileShare using StreamReader which is what I need.
-Jerry
On Sep 22, 5:27 pm, "Jerry Spence1" <1...@dfgh.comw rote:
System.File.Rea dAllLines does behind the scenes. However, I can't find a way
of setting the FileShare using StreamReader which is what I need.
Just use a FileStream to open the file and use a streamreader to read
it:
Using fs As New FileStream("fil ename.txt", FileMode.Append ,
FileAccess.Read Write, FileShare.ReadW rite)
Using rdr As New StreamReader(fs )
'User streamreader here...
End Using
End Using
Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: varlagas |
last post by:
We disabled the antivirus software but the problem persists. Any clues?
Many thanks in advance!
Panagiotis Varlagas
=======================================================================
2005-07-28-10.39.02.015001 Instance:DB2 Node:000
PID:1568(db2syscs.exe) TID:2440 Appid:0A00153A.C90B.050728083720
|
by: Jeff |
last post by:
Hi -
I'm creating an installation program that will install a VB.NET program and
an instance of MSDE on an unknown desktop (commercial application). The
install will include the MSDE redistributable files (and it will launch the
MSDE Setup.exe to install MSDE).
I've read that "Except on Win 98 and Millennium, file and print sharing must
be active"
|
by: J.S. |
last post by:
I have a text file with parameters like the following embedded in the text:
@@TextBox1@@, @@TextBox2@@, etc.
I know how to read this text file. However, I am trying to figure out how
to replace these parameters in the text file with values of the textboxes on
my Windows Form called Form1. For example, replace @@TextBox1@@ with value
of TextBox1, replace @@TextBox2@@ with value of TextBox2, replace
@@ComboBox1@@ with value of...
|
by: George |
last post by:
Hi,
I am re-writing part of my application using C#. This application starts
another process which execute a "legacy" program. This legacy program writes
to a log file and before it ends, it writes a specific string to the log file.
My original program (MKS Toolkit shell program) which keeps running "grep"
checking the "exit string" on the "log files". There are no file sharing
problem.
|
by: Alan T |
last post by:
What will be the maximum characters the string can hold?
string fileText;
fileText = File.ReadAllText("c:\temp"myText.txt");
If my file size is about 30 KB, can the fileText store all the text?
| |
by: JDeats |
last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting
and decrypting a file.
http://support.microsoft.com/kb/307010
In .NET 2.0 this approach is not fully supported (a .NET 2.0 build
with these methods, will appear to encrypt and decrypt, but the
resulting decrypted file will be corrupted. I tried encrypting a .bmp
file and then decrypting, the resulting decrypted file under .NET 2.0
is garbage, the .NET 1.1 build works...
|
by: kimiraikkonen |
last post by:
Hi,
I want to save all the item content of a listbox line by line into a
simple text file then recall them when my project is opened.
For example listbox1 contains:
That - item1
Group -item2
Is -item3
Really -item4
|
by: Clinto |
last post by:
Hi,
I am trying to find the fastest way to search a txt file for a
particular string and return the line that contains the string. I have
so for just used the most basic method. Initialized a variable as
IO.streamreader. Read each line and perform an if-then to see if
var.contains(mystring) is true or false. if true I get my string if
false it reads the next line. This takes for ever. Is there anything I
can do to speed this up?
Thanks.
|
by: amollokhande1 |
last post by:
Hi,
I am trying to read the file contents using System.IO.File.ReadAllText
After reading the file contents the special charaters (á) gets replaced with some garbage characters like "?".
To elliminate this I have used encoding along with above method
System.IO.File.ReadAllText(strFile, System.Text.Encoding.ASCII)
But still it is not working.Can anybody have the solution for this
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |