日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
針對(duì)VB.NET文件流讀、寫類文件演示實(shí)例

本人就非常喜歡對(duì)文件進(jìn)行研究,在網(wǎng)上和書上也收了許多相關(guān)的資料,下面的就是一個(gè)對(duì)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 

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

【編輯推薦】

  1. 實(shí)例講述VB.NET使用Log4Net
  2. 三分鐘學(xué)會(huì)VB.NET轉(zhuǎn)換形態(tài)
  3. VB.NET獲取硬盤信息四大法寶
  4. 講述VB.NET調(diào)用Excel的好處
  5. 簡(jiǎn)單例子概述VB.NET新窗體

網(wǎng)站名稱:針對(duì)VB.NET文件流讀、寫類文件演示實(shí)例
網(wǎng)頁鏈接:http://www.5511xx.com/article/dhchjsc.html