写入文本文件 [英] write to text file
问题描述
我有一个文本文件,我需要写入多行数据,但需要一个时间。
我怎样才能写出多行数据到文件?
示例:
i搜索服务器上的文件,如果该文件不存在于
服务器我把它写到文本文件。
然后我搜索另一个文件,如果不存在,再次写入
文本文件。
我需要使用相同的文本文件并将所有不存在的文件添加到
文件而不丢失任何文件。
我该怎么办?那个?
I have a text file that i need to write multiple lines of data to but one at
a time.
how can i write more then one line of data to the file?
example:
i do a search for a file on a server if the file does not exist on the
server i write it to text file.
then i search for another file and if that does not exist, again write to
the text file.
I need to use the same text file and add all the files that do not exist to
the file without loosing any.
how can i do that?
推荐答案
你好Mike
MSDN上的内容比你想象的要多
http://msdn.microsoft.com/library/de...gToLogFile.asp
我希望这有帮助吗?
Cor
Hi Mike
There is more on MSDN than you think
http://msdn.microsoft.com/library/de...gToLogFile.asp
I hope this helps?
Cor
*" Mike" <一个******* @ discussions.microsoft.com> scripsit:
* "Mike" <an*******@discussions.microsoft.com> scripsit:
我有一个文本文件,我需要一次写入多行数据。
我怎么能写一行以上的数据到文件?
I have a text file that i need to write multiple lines of data to but one at
a time.
how can i write more then one line of data to the file?
查看''System.IO.StreamWriter'及其''WriteLine''方法。
-
Herfried K. Wagner [MVP]
< URL:http://dotnet.mvps.org/>
Have a look at ''System.IO.StreamWriter'' and its ''WriteLine'' method.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
我认为你的问题是你需要打开附加标志
设置为True的文件,这样每次都不会覆盖文件:
Dim IOFile as IO.StreamWriter(" LogFile.txt",True)
....
IOFile.WriteLine(txtToWrite)
IOFile.Close
希望有所帮助,
-
Marc Butenko
mb******@bresnan.net
"麦克" <一个******* @ discussions.microsoft.com>在留言中写道
新闻:ON ************** @ TK2MSFTNGP11.phx.gbl ...
I think your problem is that you need to open the file with the Append flag
set to True so the file is not overwritten everytime:
Dim IOFile as IO.StreamWriter("LogFile.txt", True)
....
IOFile.WriteLine(txtToWrite)
IOFile.Close
Hope that helps,
--
Marc Butenko
mb******@bresnan.net
"Mike" <an*******@discussions.microsoft.com> wrote in message
news:ON**************@TK2MSFTNGP11.phx.gbl...
我有一个文本文件我需要一次写一行
来写多行数据。
我怎样才能在文件中写入多行数据呢?
示例:
服务器上没有文件我将其写入文本文件。
然后我搜索另一个文件,如果不存在,再次写入
文本文件。
我需要使用相同的文本文件,并将所有不存在的文件
添加到文件中,而不会丢失任何文件。
我怎么能这样做?
I have a text file that i need to write multiple lines of data to but one at a time.
how can i write more then one line of data to the file?
example:
i do a search for a file on a server if the file does not exist on the
server i write it to text file.
then i search for another file and if that does not exist, again write to
the text file.
I need to use the same text file and add all the files that do not exist to the file without loosing any.
how can i do that?
这篇关于写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!