如何实现VB.NET文件流读、写类文件
发表于:2025-11-08 作者:千家信息网编辑
千家信息网最后更新 2025年11月08日,这篇文章主要介绍如何实现VB.NET文件流读、写类文件,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!VB.NET文件流代码:Option Explicit Private m
千家信息网最后更新 2025年11月08日如何实现VB.NET文件流读、写类文件
这篇文章主要介绍如何实现VB.NET文件流读、写类文件,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
VB.NET文件流代码:
Option Explicit Private m_strFilePath As String Private m_intFileNum As Integer Private m_bytBuffer() As Byte Public Property Get FilePath() As String FilePath = m_strFilePath End Property Public Property Let FilePath(ByVal strFilePath As String) m_strFilePath = strFilePath End Property Public Property Get EOS() As Boolean If Ready() Then EOS = EOF(m_intFileNum) Else EOS = True End If End Property Public Property Get Ready() As Boolean Ready = m_intFileNum <> 0 End Property Public Function CloseFile() As Boolean If Ready() Then Close #m_intFileNum m_intFileNum = 0 CloseFile = True Else CloseFile = False End If End Function Public Function OpenFile() As Boolean On Error Goto HandleError CloseFile m_intFileNum = FreeFile Open m_strFilePath For Binary As #m_intFileNum OpenFile = True Exit Function HandleError: OpenFile = False End Function Public Property Get Position() As Long If Ready() Then Position = Loc(m_intFileNum) Else Position = -1 End If End Property Public Property Let Position(ByVal lngPosition As Long) If Ready() Then If lngPosition > 0 And lngPosition <= LOF(m_intFileNum) Then Seek #m_intFileNum, lngPosition Else RaiseError "Position", "Position invalid" End If Else RaiseError "Position" End If End Property Private Sub RaiseError(ByVal strProcedure As String, _ Optional ByVal strDescription As String = "File Not Opened") Err.Raise vbObjectError + 101, strProcedure, strDescription End Sub Public Function ReadBytes(ByVal lngCount As Long) As Byte() If Ready() Then If lngCount > 0 And lngCount + Loc(m_intFileNum) - 1 <= LOF(m_intFileNum) Then ReDim m_bytBuffer(0 To lngCount - 1) As Byte Get #m_intFileNum, , m_bytBuffer ReadBytes = m_bytBuffer Else RaiseError "ReadBytes", "Out of boundary" End If Else RaiseError "ReadBytes" End If End Function Public Function ReadText(ByVal lngCount As Long) As String ReadText = StrConv(ReadBytes(lngCount), vbUnicode) End Function Public Sub WriteBytes(ByRef bytContent() As Byte) If Ready() Then Put #m_intFileNum, , bytContent Else RaiseError "WriteBytes" End If End Sub Public Sub WriteText(ByVal strText As String) WriteBytes StrConv(strText, vbFromUnicode) End Sub Private Sub Class_Initialize() m_intFileNum = 0 End Sub Private Sub Class_Terminate() CloseFile End Sub
以上是"如何实现VB.NET文件流读、写类文件"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
文件
内容
篇文章
代码
价值
兴趣
小伙
小伙伴
更多
知识
行业
资讯
资讯频道
频道
参考
帮助
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
广州密影科技互联网有限公司
数据库学习笔记第二章关系数据库
网络安全与执法危险吗
数据库开发设计论文
实号手机号数据库
网络安全有什么方向
数字货币的核心是网络安全吗
江苏hpe服务器多少钱
软件开发公司能做么
网络安全保护技术促进开放
创建自己的服务器地址
网络安全在线承诺词
bios服务器设置ip
京东网络安全招聘
安卓模拟器 代理服务器
db2数据库管理工具
大话西游手游百度服务器哪个好
下拉框绑定数据库
方舟服务器卡
服务器管理维护做什么
软件开发需要哪些专业知识技能
apple 连接服务器验证失败
武汉互联网教育科技公司有哪些
网络安全宣传周签名活动
远程关闭服务器安全狗
软件开发流程图软件
删除数据库需要什么权限吗
京东网络安全招聘
监控管理中心服务器
服务器管理笔试题