如何一次读取一行文本并写回VB6中的另一个文件 [英] How to read one line of text at a time and write back out to another file in VB6

查看:14
本文介绍了如何一次读取一行文本并写回VB6中的另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图一次从文件A"中读取一行,对该行进行更改,然后将其写回到文件B"中.随我添加文件B".我在网上找到了很多信息,但没有一个与我正在寻找的信息相匹配.

I'm trying to read from file "A" one line at a time, make changes to that line, and write it back out to file "B". Appending File "B" as I go. I've found plenty of info on the web but none of it matches what I'm looking for.

关于如何实现这一点的任何想法?

Any ideas on how to implement this?

推荐答案

我很快就把这些放在一起,但应该很容易阅读.您打开要读取的文件和要写入的文件,并对其进行迭代.

I threw this together real quick, but it should be pretty easy to read. You open your file to read, and your file to write to, and iterate through it.

Dim fileIn As Integer
Dim fileOut As Integer
Dim sLine As String

fileIn = FreeFile

Open "C:\Temp\input.txt" For Input As fileIn

fileOut = FreeFile

Open "C:\Temp\output.txt" For Append As fileOut

Do While Not EOF(fileIn)
    Line Input #fileIn, sLine
    sLine = sLine & " has been changed"  ' This is where you'd make your changes
    Print #fileOut, sLine
Loop

Close fileIn
Close fileOut

这篇关于如何一次读取一行文本并写回VB6中的另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆