自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

針對VB.NET文件流讀、寫類文件演示實例

開發(fā) 后端
文章主要演示了一個關(guān)于VB.NET文件流讀、寫的類文件的案例,代碼完整清晰,喜歡研究的朋友可以下載回去好好研究一下。

本人就非常喜歡對文件進行研究,在網(wǎng)上和書上也收了許多相關(guān)的資料,下面的就是一個對VB.NET文件流讀、寫的類文件。大家可以下載回去研究一下。

VB.NET文件流代碼:

  1. Option Explicit  
  2. Private m_strFilePath As String  
  3. Private m_intFileNum As Integer  
  4. Private m_bytBuffer() As Byte  
  5.  
  6. Public Property Get FilePath() As String  
  7. FilePath = m_strFilePath 
  8. End Property  
  9.  
  10. Public Property Let FilePath(ByVal strFilePath As String)  
  11. m_strFilePath = strFilePath  
  12. End Property  
  13.  
  14. Public Property Get EOS() As Boolean  
  15. If Ready() Then  
  16. EOS = EOF(m_intFileNum)  
  17. Else  
  18. EOS = True 
  19. End If  
  20. End Property  
  21.  
  22. Public Property Get Ready() As Boolean  
  23. Ready = m_intFileNum <> 0  
  24. End Property  
  25.  
  26. Public Function CloseFile() As Boolean  
  27. If Ready() Then  
  28. Close #m_intFileNum  
  29. m_intFileNum = 0 
  30. CloseFile = True 
  31. Else  
  32. CloseFile = False 
  33. End If  
  34. End Function  
  35.  
  36. Public Function OpenFile() As Boolean  
  37. On Error Goto HandleError  
  38. CloseFile  
  39. m_intFileNum = FreeFile 
  40. Open m_strFilePath For Binary As #m_intFileNum  
  41. OpenFile = True 
  42. Exit Function  
  43. HandleError:  
  44. OpenFile = False 
  45. End Function  
  46.  
  47. Public Property Get Position() As Long  
  48. If Ready() Then  
  49. Position = Loc(m_intFileNum)  
  50. Else  
  51. Position = -1  
  52. End If  
  53. End Property  
  54.  
  55. Public Property Let Position(ByVal lngPosition As Long)  
  56. If Ready() Then  
  57. If lngPosition > 0 And lngPosition <= LOF(m_intFileNum) Then  
  58. Seek #m_intFileNum, lngPosition  
  59. Else  
  60. RaiseError "Position", "Position invalid"  
  61. End If  
  62. Else  
  63. RaiseError "Position"  
  64. End If  
  65. End Property  
  66.  
  67. Private Sub RaiseError(ByVal strProcedure As String, _  
  68. Optional ByVal strDescription As String = "File Not Opened")  
  69. Err.Raise vbObjectError + 101, strProcedure, strDescription  
  70. End Sub  
  71.  
  72. Public Function ReadBytes(ByVal lngCount As Long) As Byte()  
  73.  
  74. If Ready() Then  
  75. If lngCount > 0 And lngCount + Loc(m_intFileNum) - 1 <= LOF(m_intFileNum) Then  
  76. ReDim m_bytBuffer(0 To lngCount - 1) As Byte  
  77. Get #m_intFileNum, , m_bytBuffer  
  78. ReadBytes = m_bytBuffer 
  79. Else  
  80. RaiseError "ReadBytes", "Out of boundary"  
  81. End If  
  82. Else  
  83. RaiseError "ReadBytes"  
  84. End If  
  85. End Function  
  86.  
  87. Public Function ReadText(ByVal lngCount As Long) As String  
  88. ReadText = StrConv(ReadBytes(lngCount), vbUnicode)  
  89. End Function  
  90.  
  91. Public Sub WriteBytes(ByRef bytContent() As Byte)  
  92. If Ready() Then  
  93. Put #m_intFileNum, , bytContent  
  94. Else  
  95. RaiseError "WriteBytes"  
  96. End If  
  97. End Sub  
  98.  
  99. Public Sub WriteText(ByVal strText As String)  
  100. WriteBytes StrConv(strText, vbFromUnicode)  
  101. End Sub  
  102.  
  103. Private Sub Class_Initialize()  
  104. m_intFileNum = 0 
  105. End Sub  
  106.  
  107. Private Sub Class_Terminate()  
  108. CloseFile  
  109. End Sub 

上述的代碼看懂了嗎?以后我還會發(fā)關(guān)于VB.NET文件流相關(guān)操作的代碼實例,希望大家繼續(xù)關(guān)注。

【編輯推薦】

  1. 實例講述VB.NET使用Log4Net
  2. 三分鐘學(xué)會VB.NET轉(zhuǎn)換形態(tài)
  3. VB.NET獲取硬盤信息四大法寶
  4. 講述VB.NET調(diào)用Excel的好處
  5. 簡單例子概述VB.NET新窗體
責(zé)任編輯:田樹 來源: 博客
相關(guān)推薦

2009-11-02 09:45:23

VB.NET文件系統(tǒng)對

2009-10-27 10:58:00

VB.NET文件名排序

2009-11-03 16:43:54

VB.NET拖放文件

2009-10-23 14:31:05

VB.NET類定義

2009-10-22 09:20:46

VB.NET Proc

2009-11-02 12:35:10

VB.NET追加文件

2009-10-29 15:16:02

VB.NET文件傳送

2009-11-03 11:06:40

VB.NET事件

2009-10-26 09:50:20

VB.NET Star

2009-10-29 13:46:14

VB.NET DES加

2010-01-15 10:05:35

VB.NET文件對象

2009-10-20 09:39:04

VB.NET Butt

2010-01-21 16:17:32

VB.NET文件對象

2009-10-28 13:24:25

VB.NET文件

2009-11-02 09:21:04

VB.NET文件系統(tǒng)

2009-10-29 15:02:04

VB.NET文件排序

2009-10-29 15:28:38

VB.NET文件操作

2010-01-15 19:04:09

2010-01-20 13:42:10

VB.NET訪問INIGetPrivateP

2010-01-12 16:20:44

VB.NET類
點贊
收藏

51CTO技術(shù)棧公眾號