vb怎样进行文件操作 代码
2个回答
展开全部
Private Sub Command1_Click()
'创建并写入TXT文件
Open "D:/1.txt" For Append As #1
Print #1, "Hello Wolrd!"
Close #1
'打开并读取数据
Open "D:/1.txt" For Input As #1
Dim a As String
Line Input #1, a
MsgBox "这个文件中储存的数据是:" & vbCrLf & " " & a, 48, "提示"
Close #1
End Sub
'创建并写入TXT文件
Open "D:/1.txt" For Append As #1
Print #1, "Hello Wolrd!"
Close #1
'打开并读取数据
Open "D:/1.txt" For Input As #1
Dim a As String
Line Input #1, a
MsgBox "这个文件中储存的数据是:" & vbCrLf & " " & a, 48, "提示"
Close #1
End Sub
展开全部
下面的 VBScript 示例示范了如何打开文件,和如何写数据到文件中并从文件读取数据:
Sub ReadFiles
Dim fso, f1, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
' 写一行。
Response.Write "Writing file <br>"
f1.WriteLine "Hello World"
f1.WriteBlankLines(1)
f1.Close
' 读取文件的内容。
Response.Write "Reading file <br>"
Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
s = ts.ReadLine
Response.Write "File contents = '" & s & "'"
ts.Close
End Sub
看看帮助文件吧!
Sub ReadFiles
Dim fso, f1, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
' 写一行。
Response.Write "Writing file <br>"
f1.WriteLine "Hello World"
f1.WriteBlankLines(1)
f1.Close
' 读取文件的内容。
Response.Write "Reading file <br>"
Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
s = ts.ReadLine
Response.Write "File contents = '" & s & "'"
ts.Close
End Sub
看看帮助文件吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询