mustish1
asked on
read data line by line from a textfile
Hi: Can any one please tell me how to i read data line by line from a textfile and then write into another textfile?
Thanks.
Thanks.
ASKER
Thanks only in VB6
Here's VB.NET:
Dim inLine as String
'To read
Dim sr As New System.IO.StreamReader("c: \temp\myfi le.txt")
Do
inLine = sr.ReadLine
Loop until sr.EndOfStream = True
sr.Close
'To write
Dim sw as New System.IO.StreamWriter("c: \temp\myfi le.txt")
sw.WriteLine("Cool!")
sw.Close()
Dim inLine as String
'To read
Dim sr As New System.IO.StreamReader("c:
Do
inLine = sr.ReadLine
Loop until sr.EndOfStream = True
sr.Close
'To write
Dim sw as New System.IO.StreamWriter("c:
sw.WriteLine("Cool!")
sw.Close()
ASKER
Thanks can you please tell me how to i read one line from firstfile.txt and write into second file.txt until firstfile.txt is at end.
Dim fso as new FileSystemObject
Dim ts as TextStream
Dim inLine as string
'To Read:
set ts = fso.OpenTextFile("c:\temp\ firstfile. txt", ForReading)
Do
inLine = ts.ReadLine
'Process with your line.
Loop Until ts.AtEndOfStream = True
ts.close
'To Write:
set ts = fso.OpenTextFile("c:\temp\ secondfile .txt", ForWriting)
ts.WriteLine "Cool!"
ts.Close
Dim fso as new FileSystemObject
Dim ts as TextStream
Dim inLine as string
'To Read:
set ts = fso.OpenTextFile("c:\temp\
Do
inLine = ts.ReadLine
'Process with your line.
Loop Until ts.AtEndOfStream = True
ts.close
'To Write:
set ts = fso.OpenTextFile("c:\temp\
ts.WriteLine "Cool!"
ts.Close
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't forget to add the Project Reference, or you won't be able to use the FileSystemObject:
Add a reference to the Microsoft Scripting Runtime Library (scrrun.dll) Project / References.
Add a reference to the Microsoft Scripting Runtime Library (scrrun.dll) Project / References.
VB6: Add a reference to the Microsoft Scripting Runtime Library (scrrun.dll) Project / References.
Then, code like this:
Dim fso as new FileSystemObject
Dim ts as TextStream
Dim inLine as string
'To Read:
set ts = fso.OpenTextFile("c:\temp\
Do
inLine = ts.ReadLine
'Process with your line.
Loop Until ts.AtEndOfStream = True
ts.close
'To Write:
set ts = fso.OpenTextFile("c:\temp\
ts.WriteLine "Cool!"
ts.Close
Do you need it in VB.NET?