|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 Nettan wrote:
> What is the best way to write to a textfile, is it with FileSystemObject or StreamWriter. Absolutely.> with StreamWriter? 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. Phill W. wrote:
>> What is the best way to write to a textfile, is it with Or in VB2005, I prefer IO.File.WriteAllText and IO.File.AppendAllText, which >> FileSystemObject or with StreamWriter? > > StreamWriter. Absolutely. reduces most textfile operations to one line of code. -- (O)enone "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> schrieb: That's true, with the exception that I'd continue to use the FSO in projects >> 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. 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/> 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 Show quoteHide quote "Nettan" <Net***@discussions.microsoft.com> schreef in bericht news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... > Hi > > What is the best way to write to a textfile, is it with FileSystemObject > or > with StreamWriter? > > Thanks /Nettan 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 Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:OqKkQSbHHHA.4068@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" <Net***@discussions.microsoft.com> schreef in bericht > news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... >> Hi >> >> What is the best way to write to a textfile, is it with FileSystemObject >> or >> with StreamWriter? >> >> Thanks /Nettan > > 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. ------------------------------------ Show quoteHide quote "Garry" <garrygrol***@gmail.com> wrote in message news:uCBAQvgHHHA.4760@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]" <notmyfirstn***@planet.nl> wrote in message > news:OqKkQSbHHHA.4068@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" <Net***@discussions.microsoft.com> schreef in bericht >> news:ACCA2908-9A0A-4484-98A5-CE0A6AFEBA6D@microsoft.com... >>> Hi >>> >>> What is the best way to write to a textfile, is it with >>> FileSystemObject or >>> with StreamWriter? >>> >>> Thanks /Nettan >> >> > > On 2006-12-11, Nettan <Net***@discussions.microsoft.com> wrote:
> Hi I have to respectfully disagree with Cor on this one. Using the FSO from .NET> > What is the best way to write to a textfile, is it with FileSystemObject or > with StreamWriter? > > Thanks /Nettan 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 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 Show quoteHide quote "Tom Shelton" <tom_shel***@comcastXXXXXXX.net> schreef in bericht news:tsednWWaVPeECOLYnZ2dnUVZ_vvinZ2d@comcast.com... > On 2006-12-11, Nettan <Net***@discussions.microsoft.com> wrote: >> 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
What Does This Mean?
Computer Name - Best way to obtain this VB.Net Settings in VB.NET/WinForms How to Add *AND* Process Checkbox Column in a DataGridView? Re: .net Visual Studio A Simple SQL Result displayed into a TextBox Keeping Code Snippets? Placeholder Control Shell( ) inconsistency with actual windows interfac how can I tell if it is a folder or a non-folder file |
|||||||||||||||||||||||