473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Dec 11 '06 #1
12 3113
Nettan wrote:
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.
Dec 11 '06 #2
Phill W. wrote:
>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
Dec 11 '06 #3
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kschrieb:
>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/>

Dec 11 '06 #4
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:
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kschrieb:
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/>
Dec 11 '06 #5
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" <Ne****@discussions.microsoft.comschreef in bericht
news:AC**********************************@microsof t.com...
Hi

What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?

Thanks /Nettan

Dec 12 '06 #6
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]" <no************@planet.nlwrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
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" <Ne****@discussions.microsoft.comschreef in bericht
news:AC**********************************@microsof t.com...
>Hi

What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?

Thanks /Nettan


Dec 12 '06 #7
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:
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]" <no************@planet.nlwrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
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" <Ne****@discussions.microsoft.comschreef in bericht
news:AC**********************************@microsof t.com...
Hi

What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?

Thanks /Nettan
Dec 12 '06 #8
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:
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]" <no************@planet.nlwrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
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" <Ne****@discussions.microsoft.comschreef in bericht
news:AC**********************************@microsof t.com...
Hi

What is the best way to write to a textfile, is it with FileSystemObject
or
with StreamWriter?

Thanks /Nettan
Dec 12 '06 #9
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" <ga**********@gmail.comwrote in message
news:uC**************@TK2MSFTNGP03.phx.gbl...
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]" <no************@planet.nlwrote in message
news:Oq**************@TK2MSFTNGP03.phx.gbl...
>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" <Ne****@discussions.microsoft.comschreef in bericht
news:AC**********************************@microso ft.com...
>>Hi

What is the best way to write to a textfile, is it with
FileSystemObject or
with StreamWriter?

Thanks /Nettan



Dec 12 '06 #10
On 2006-12-11, Nettan <Ne****@discussions.microsoft.comwrote:
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
Dec 13 '06 #11
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" <to*********@comcastXXXXXXX.netschreef in bericht
news:ts******************************@comcast.com. ..
On 2006-12-11, Nettan <Ne****@discussions.microsoft.comwrote:
>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

Dec 13 '06 #12
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:
On 2006-12-11, Nettan <Ne****@discussions.microsoft.comwrote:
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
Dec 13 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Laiverd.COM | last post by:
Currently working on a site that requires multiple different styles for all kind of things (tables, link colors etc.) and am suddenly ;-) wondering what would be the wise approach: have all these...
1
by: Micheal Corleone | last post by:
Hey guys. Anybody has an idea how to write data from mysql source into a textfile? Thanks for help. ------------------------------- Fav pages: PSP Spiele: http://www.psp-spiele.net
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
7
by: CJ | last post by:
Hello! I want to read a large text file (100 mb) and from with in the file i want to take out some lines on a spesific kriteria and make new files. eks. inputfile: 123 hello.. 123 more......
32
by: David Isaac | last post by:
I have no experience with database applications. This database will likely hold only a few hundred items, including both textfiles and binary files. I would like a pure Python solution to the...
6
by: ericunfuk | last post by:
Hi ALL, I want to read a binary file(it's pic.tif file, I guess it's binary file?), then write it to a new file), I have several questions about this process: When I use fread() to read a...
7
by: Prem Parekh | last post by:
I need code that can parse data from log file. The log is pipe delimited and in following format: time=2006-11-03 13:13:56| fw=199.23.48.120| user=tjolen| realm=EMEA| roles=Network Connect|...
9
by: Stef Mientki | last post by:
hello, I want to search multiple textfiles (python source files) for a specific word. I can find all files, open them and do a search, but I guess that will be rather slow. I couldn't find...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.