Diese Funktionen ließt und schreibt Textdateien in verscheidene Formate.
Sollten selbtserklärend sein.
Falls nicht, bitte melden ;)
Änderungen von Tim Hartwig eingefügt (siehe Kommentar)
Public Function TXT2ListOfString(ByVal FullPath As String) As List(Of String)
Dim lst As New List(Of String)
If IO.File.Exists(FullPath) Then lst.AddRange(IO.File.ReadAllLines(FullPath, System.Text.Encoding.Default))
Return lst
End Function
Public Function ListOfString2TXT(ByVal FullPath As String, ByVal lst As List(Of String)) As Boolean
Dim f As New IO.FileInfo(FullPath)
If f.Directory.Exists = True Then
IO.File.WriteAllLines(FullPath, lst.ToArray, System.Text.Encoding.Default)
Return True
End If
Return False
End Function
Public Function TXT2StringArray(ByVal FullPath As String) As String()
Dim strar() As String = Nothing
If IO.File.Exists(FullPath) Then strar = IO.File.ReadAllLines(FullPath, System.Text.Encoding.Default)
Return strar
End Function
Public Function StringArray2TXT(ByVal FullPath As String, ByVal strar() As String) As Boolean
Dim f As New IO.FileInfo(FullPath)
If f.Directory.Exists = True Then
IO.File.WriteAllLines(FullPath, strar, System.Text.Encoding.Default)
Return True
End If
Return False
End Function
Public Function TXT2ByteArray(ByVal FullPath As String) As Byte()
Dim byAr() As Byte = Nothing
If IO.File.Exists(FullPath) Then byAr = IO.File.ReadAllBytes(FullPath)
Return byAr
End Function
Public Function ByteArray2TXT(ByVal FullPath As String, ByVal byAr() As Byte) As Boolean
Dim f As New IO.FileInfo(FullPath)
If f.Directory.Exists = True Then
IO.File.WriteAllBytes(FullPath, byAr)
Return True
End If
Return False
End Function
Public Function TXT2String(ByVal FullPath As String) As String
Dim str As String = ""
If IO.File.Exists(FullPath) Then str = IO.File.ReadAllText(FullPath, System.Text.Encoding.Default)
Return str
End Function
Public Function String2TXT(ByVal FullPath As String, ByVal str As String) As Boolean
Dim f As New IO.FileInfo(FullPath)
If f.Directory.Exists = True Then
IO.File.WriteAllText(FullPath, str, System.Text.Encoding.Default)
Return True
End If
Return False
End Function
2 Kommentare zum Snippet