Best way to write to textfiles? | | |
Hi
What is the best way to write to a textfile, is it with FileSystemObject or
with StreamWriter?
Thanks /Nettan | | | | re: Best way to write to textfiles?
Nettan wrote: Quote:
What is the best way to write to a textfile, is it with FileSystemObject or
with StreamWriter?
StreamWriter. Absolutely.
The FileSystemObject was, at best, a feeble crutch for ASP, which didn't
have any other way of getting into the file system.
The functionality in the System.IO Namespace simply blows the FSO away.
Regards,
Phill W. | | | | re: Best way to write to textfiles?
Phill W. wrote: Quote: Quote:
>What is the best way to write to a textfile, is it with
>FileSystemObject or with StreamWriter?
>
StreamWriter. Absolutely.
Or in VB2005, I prefer IO.File.WriteAllText and IO.File.AppendAllText, which
reduces most textfile operations to one line of code.
--
(O)enone | | | | re: Best way to write to textfiles?
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kschrieb: Quote: Quote:
>What is the best way to write to a textfile, is it with FileSystemObject
>or with StreamWriter?
>
StreamWriter. Absolutely.
>
The FileSystemObject was, at best, a feeble crutch for ASP, which didn't
have any other way of getting into the file system.
>
The functionality in the System.IO Namespace simply blows the FSO away.
That's true, with the exception that I'd continue to use the FSO in projects
migrated from VB6 until the code gets rewritten.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/> | | | | re: Best way to write to textfiles?
yeah.. why should you rewrite it at all?
keep it in vb6 until MS decided the fate of VB
I heard it's all changing again in another year or so
-Aaron
Herfried K. Wagner [MVP] wrote: Quote:
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kschrieb: Quote: Quote:
What is the best way to write to a textfile, is it with FileSystemObject
or with StreamWriter?
StreamWriter. Absolutely.
The FileSystemObject was, at best, a feeble crutch for ASP, which didn't
have any other way of getting into the file system.
The functionality in the System.IO Namespace simply blows the FSO away.
>
That's true, with the exception that I'd continue to use the FSO in projects
migrated from VB6 until the code gets rewritten.
>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
| | | | re: Best way to write to textfiles?
Nettan,
The best way is that one which fits you the best. There are no best ones in
this kind of open questions, all the possibilities are not created for
fun..
Cor
"Nettan" <Nettan@discussions.microsoft.comschreef in bericht
news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... Quote:
Hi
>
What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?
>
Thanks /Nettan
| | | | re: Best way to write to textfiles?
Well, can someone point to an article comparing the various methods so that
I can get some serious info.
In VB6, the FSO would, on some computers, activate an anti script defensive
program, (Malicious script detected), so I used to use the most 'basic of
basic' - 'Open for output' type VB methods which were unbelievably fast.
A link to comparative text as per the available methods would be much
appreciated.
Garry
"Cor Ligthert [MVP]" <notmyfirstname@planet.nlwrote in message
news:OqKkQSbHHHA.4068@TK2MSFTNGP03.phx.gbl... Quote:
Nettan,
>
The best way is that one which fits you the best. There are no best ones
in this kind of open questions, all the possibilities are not created for
fun..
>
Cor
>
"Nettan" <Nettan@discussions.microsoft.comschreef in bericht
news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... Quote:
>Hi
>>
>What is the best way to write to a textfile, is it with FileSystemObject
>or
>with StreamWriter?
>>
>Thanks /Nettan
>
>
| | | | re: Best way to write to textfiles?
is this a VB6 problem
Malicious script detected
or is it some C++ fag that doesn't respect VB6 that put a crappy
security mechanism on it?
kinda like the triple prompts when opening MS Access.. or the prompts
to send mail automagically using the damn outlook object model?
it's all because some C++ fag was in control and crippled VB.
And I've never seen this message.. except from like Norton / Symantec
and everyone knows that they eat a dick right?
-Aaron
Garry wrote: Quote:
Well, can someone point to an article comparing the various methods so that
I can get some serious info.
>
In VB6, the FSO would, on some computers, activate an anti script defensive
program, (Malicious script detected), so I used to use the most 'basic of
basic' - 'Open for output' type VB methods which were unbelievably fast.
>
A link to comparative text as per the available methods would be much
appreciated.
>
Garry
>
>
>
"Cor Ligthert [MVP]" <notmyfirstname@planet.nlwrote in message
news:OqKkQSbHHHA.4068@TK2MSFTNGP03.phx.gbl... Quote:
Nettan,
The best way is that one which fits you the best. There are no best ones
in this kind of open questions, all the possibilities are not created for
fun..
Cor
"Nettan" <Nettan@discussions.microsoft.comschreef in bericht
news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... Quote:
Hi
>
What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?
>
Thanks /Nettan
| | | | re: Best way to write to textfiles?
and do you really think that open for output is the fastest?
you got any benchmarks to share?
I thought that the textstream was supposed to be faster
in a perfect world; everything would be a performance decision.
is X or Y faster; use X.
I think that performance-- ease of development included-- is a limiting
factor and end user performance is fast enough in almost anything that
we do.
Garry wrote: Quote:
Well, can someone point to an article comparing the various methods so that
I can get some serious info.
>
In VB6, the FSO would, on some computers, activate an anti script defensive
program, (Malicious script detected), so I used to use the most 'basic of
basic' - 'Open for output' type VB methods which were unbelievably fast.
>
A link to comparative text as per the available methods would be much
appreciated.
>
Garry
>
>
>
"Cor Ligthert [MVP]" <notmyfirstname@planet.nlwrote in message
news:OqKkQSbHHHA.4068@TK2MSFTNGP03.phx.gbl... Quote:
Nettan,
The best way is that one which fits you the best. There are no best ones
in this kind of open questions, all the possibilities are not created for
fun..
Cor
"Nettan" <Nettan@discussions.microsoft.comschreef in bericht
news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... Quote:
Hi
>
What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?
>
Thanks /Nettan
| | | | re: Best way to write to textfiles?
Here's one method. This is quick. You can also check out
the StreamReader and StreamWriter classes.
This reads a file and splits it into lines using the CrLf characters
that are (hopefully) at the end of each line.
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = File.ReadAllText("C:\data.txt").Split(crlfs, _
StringSplitOptions.None)
Dim numOfLines as Integer = lines.Length
If you want to do the opposite, you can do this:
Dim newText as String = String.Join(ControlChars.CrLf, _
lines, 1, lines.Length - 1)
File.WriteAllText("C:\Data2.txt", newText)
Robin S.
------------------------------------
"Garry" <garrygrolman@gmail.comwrote in message
news:uCBAQvgHHHA.4760@TK2MSFTNGP03.phx.gbl... Quote:
Well, can someone point to an article comparing the various methods so
that I can get some serious info.
>
In VB6, the FSO would, on some computers, activate an anti script
defensive program, (Malicious script detected), so I used to use the
most 'basic of basic' - 'Open for output' type VB methods which were
unbelievably fast.
>
A link to comparative text as per the available methods would be much
appreciated.
>
Garry
>
>
>
"Cor Ligthert [MVP]" <notmyfirstname@planet.nlwrote in message
news:OqKkQSbHHHA.4068@TK2MSFTNGP03.phx.gbl... Quote:
>Nettan,
>>
>The best way is that one which fits you the best. There are no best
>ones in this kind of open questions, all the possibilities are not
>created for fun..
>>
>Cor
>>
>"Nettan" <Nettan@discussions.microsoft.comschreef in bericht
>news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... Quote:
>>Hi
>>>
>>What is the best way to write to a textfile, is it with
>>FileSystemObject or
>>with StreamWriter?
>>>
>>Thanks /Nettan
>>
>>
>
>
| | | | re: Best way to write to textfiles?
On 2006-12-11, Nettan <Nettan@discussions.microsoft.comwrote: Quote:
Hi
>
What is the best way to write to a textfile, is it with FileSystemObject or
with StreamWriter?
>
Thanks /Nettan
I have to respectfully disagree with Cor on this one. Using the FSO from .NET
is really a lot of un-needed overhead.
Here are my personal rules for file handling...
Forget the FSO. You don't need it and it just introduces the extra overhead
of COM interop, on one of those operations that can be one of the big bottle
necks in an applications performance - File IO.
Forget about the VB.NET FileXXX functions. They are probably slower then the
FSO :) No, I haven't done any benchmarks to compare the speeds - just playing
a bit.
So, that leaves you with the objects from System.IO. So, my advice is to get
to know System.IO real well and forget the other file access methods.
--
Tom Shelton | | | | re: Best way to write to textfiles?
Tom,
I was not particulary looking at those, I have read it as
What is the best way to write to a textfile, is it with FileSystemObject or
with StreamWriter?
The second part was in my opinion less important than the first, in other
words I did not read:
What is the better way to write a textfile, is it with FileSystemObject or
with Stream Writer.
In this context we full agree again.
Probably my way of reading English,
Cor
"Tom Shelton" <tom_shelton@comcastXXXXXXX.netschreef in bericht
news:tsednWWaVPeECOLYnZ2dnUVZ_vvinZ2d@comcast.com. .. Quote:
On 2006-12-11, Nettan <Nettan@discussions.microsoft.comwrote: Quote:
>Hi
>>
>What is the best way to write to a textfile, is it with FileSystemObject
>or
>with StreamWriter?
>>
>Thanks /Nettan
>
I have to respectfully disagree with Cor on this one. Using the FSO from
.NET
is really a lot of un-needed overhead.
>
Here are my personal rules for file handling...
>
Forget the FSO. You don't need it and it just introduces the extra
overhead
of COM interop, on one of those operations that can be one of the big
bottle
necks in an applications performance - File IO.
>
Forget about the VB.NET FileXXX functions. They are probably slower then
the
FSO :) No, I haven't done any benchmarks to compare the speeds - just
playing
a bit.
>
So, that leaves you with the objects from System.IO. So, my advice is to
get
to know System.IO real well and forget the other file access methods.
>
--
Tom Shelton
| | | | re: Best way to write to textfiles?
Tom
if it ain't broke don't fix it
I just wish those dipshits in Redmond had some real world experience
and decided not to change EVERYTHING
it's not like they changed 1 or 2 or 10 things.. every single fucking
language just HAD TO CHANGE DIDNT IT?
those fucking dipshits in Redmond should just STFU and make our
existing libraries _FASTER_
-Aaron
Tom Shelton wrote: Quote:
On 2006-12-11, Nettan <Nettan@discussions.microsoft.comwrote: Quote:
Hi
What is the best way to write to a textfile, is it with FileSystemObject or
with StreamWriter?
Thanks /Nettan
>
I have to respectfully disagree with Cor on this one. Using the FSO from .NET
is really a lot of un-needed overhead.
>
Here are my personal rules for file handling...
>
Forget the FSO. You don't need it and it just introduces the extra overhead
of COM interop, on one of those operations that can be one of the big bottle
necks in an applications performance - File IO.
>
Forget about the VB.NET FileXXX functions. They are probably slower then the
FSO :) No, I haven't done any benchmarks to compare the speeds - just playing
a bit.
>
So, that leaves you with the objects from System.IO. So, my advice is to get
to know System.IO real well and forget the other file access methods.
>
--
Tom Shelton
|  | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|