请问如何用vb.net生成.txt文件,并且向里面添加内容?

Redsun248 2009-05-11 04:42:24
请问如何用vb.net生成.txt文件,并且向里面添加内容?
...全文
951 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuhuwy 2009-05-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ASDFY 的回复:]
写入:
Dim Str1 As String
FileOpen(1, Application.StartupPath + "\YouName.txt", OpenMode.Output)
            Print(1, Str1)
            FileClose(1)
            msgbox Str1

读出:
Dim Str1 As String
        FileOpen(1, Application.StartupPath + "\YouName.txt", OpenMode.Input) '打开文件
        Input(1, Str1) '读入要显示的字符串
        FileClose(1)
        msg…
[/Quote]
正解!
joeandlily 2009-05-12
  • 打赏
  • 举报
回复
察看StreamReader,StreamWriter
TextReader,TextWriter
actoractor 2009-05-11
  • 打赏
  • 举报
回复
UP
Redsun248 2009-05-11
  • 打赏
  • 举报
回复
Imports System
Imports System.IO




Dim sw As StreamWriter = New StreamWriter("C:\TestFile.txt", True)
'写入文件
sw.Write("This is the ")
sw.WriteLine("header for the file.")
sw.Close()

'读取文件


Dim SOpenFile As StreamReader = New StreamReader("C:\TestFile.txt")
Dim Sline As String

Do While SOpenFile.Peek() > 0

Sline = SOpenFile.ReadLine()

Loop

SOpenFile.Close()

SOpenFile = Nothing





古今多少事 2009-05-11
  • 打赏
  • 举报
回复
写入:
Dim Str1 As String
FileOpen(1, Application.StartupPath + "\YouName.txt", OpenMode.Output)
Print(1, Str1)
FileClose(1)
msgbox Str1

读出:
Dim Str1 As String
FileOpen(1, Application.StartupPath + "\YouName.txt", OpenMode.Input) '打开文件
Input(1, Str1) '读入要显示的字符串
FileClose(1)
msgbox Str1
古今多少事 2009-05-11
  • 打赏
  • 举报
回复
写入:
Dim Str1 As String
FileOpen(1, Application.StartupPath + "\Str1.txt", OpenMode.Output)
Print(1, Str1)
FileClose(1)
msgbox Str1

读出:
Dim Str1 As String
FileOpen(1, Application.StartupPath + "\Str1.txt", OpenMode.Input) '打开文件
Input(1, Str1) '读入要显示的字符串
FileClose(1)
msgbox Str1
Redsun248 2009-05-11
  • 打赏
  • 举报
回复
那如何读取已知.txt文件的内容呢?
yurengang 2009-05-11
  • 打赏
  • 举报
回复
Dim fs As New System.IO.FileStream("", IO.FileMode.Create)
Dim sw As New System.IO.StreamWriter(fs)
sw.Write("内容")
a854468521 2009-05-11
  • 打赏
  • 举报
回复
My.Computer.FileSystem.WriteAllText("文件途径", "文件内容", False, System.Text.Encoding.Default)

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧