소프트웨어 를 개발 할 때 일부 데이터 의 다른 저장 방식
2360 단어 vb.net
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Text.RegularExpressions
Public Class ClsFile
#Region " "
Public Sub CreateDirtory(ByVal tPath As String)
Dim _Fol As String = Regex.Match(tPath, "(.*?)[\\|\/][^\\/]+$").Groups(1).Value
If Not My.Computer.FileSystem.DirectoryExists(_Fol) Then
My.Computer.FileSystem.CreateDirectory(_Fol)
End If
End Sub
#End Region
#Region " / "
Public Function SaveStruct(ByVal tCo As Object, ByVal tPath As String)
CreateDirtory(tPath)
Dim fs As New FileStream(tPath, FileMode.Create)
Dim formatter As New BinaryFormatter
Try
formatter.Serialize(fs, tCo)
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
Throw
Finally
fs.Close()
End Try
End Function
Public Function ReadStruct(ByVal tPath As String) As Object
Dim fs As New FileStream(tPath, FileMode.Open)
Try
Dim formatter As New BinaryFormatter
Return formatter.Deserialize(fs)
Return ReadStruct
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
Throw
Finally
fs.Close()
End Try
End Function
#End Region
End Class
사용 방법:
‘ ,** , **
Structure dbSce
Public str As String '
Public list() As String '
Public htable As Hashtable
……
End Structure
Public ClsF As New ClsFile
Public db As dbSce
'
db.str="123"
……
ClsF.SaveStruct(db, Application.StartupPath & "\db.dat")'
'
db= ClsF.ReadStruct(Application.StartupPath & "\db.dat")
dim title as string = db.str
……
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
vb.net 암호 가 복잡 한 지 검증 하 는 방법안전 한 시스템 에서 비밀 번 호 를 사용 하여 사용자 에 게 권한 을 부여 할 수 있 습 니 다.그러나 비밀 번 호 는 권한 이 부여 되 지 않 은 사용자 가 추측 하기 어 려 울 것 이다.공격 자 는 사전 공격 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.