001集—创建、写入、读取文件fileopen函数——vb.net

此实例为在指定路径下创建一个txt文本文件,在文本文件内输入文字,并弹窗显示输入文字,代码如下: 


Public Class Form1
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim testcontent As String
        FileOpen(5, "d:\5.txt", OpenMode.Append)
        Print(5, "我的")
        Write(5, "一行")
        WriteLine(5, TAB(5), "tab")
        WriteLine(5, SPC(5), "空格")
        FileClose(5)
        ' FileOpen(2, "d:\3.txt", OpenMode.Output)
        FileOpen(5, "d:\5.txt", OpenMode.Input)

        Input(5, testcontent)

        FileClose(5)
        MsgBox(testcontent)
    End Sub
End Class

 运行结果:

vb中打开文件为open函数,在vb.net中,函数改为fileopen。

此示例演示函数的各种 FileOpen 用法,以启用文件的输入和输出。

以下代码在Input模式下打开文件TestFile

VB复制

FileOpen(1, "TESTFILE", OpenMode.Input)
' Close before reopening in another mode.
FileClose(1)

本示例仅在 Binary 模式下打开文件以执行写入操作。

VB复制

FileOpen(1, "TESTFILE", OpenMode.Binary, OpenAccess.Write)
' Close before reopening in another mode.
FileClose(1)

以下示例在 Random 模式下打开文件。 文件包含结构 Person的记录。

VB复制

Structure Person
    <VBFixedString(30)> Dim Name As String
    Dim ID As Integer
End Structure
Public Sub ExampleMethod()
    ' Count 30 for the string, plus 4 for the integer.
    FileOpen(1, "TESTFILE", OpenMode.Random, , , 34)
    ' Close before reopening in another mode.
    FileClose(1)
End Sub

此代码示例在 Output 模式下打开文件;任何进程都可以读取或写入文件。

VB复制

FileOpen(1, "TESTFILE", OpenMode.Output, OpenAccess.Default, OpenShare.Shared)
' Close before reopening in another mode.
FileClose(1)

此代码示例在 Binary 读取模式下打开文件;其他进程无法读取文件。

VB复制

FileOpen(1, "TESTFILE", OpenMode.Binary, OpenAccess.Read,
   OpenShare.LockRead)

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值