hi
Ich hatte vor lanmger zeit auch "solche" Probleme und daher das "entwickelt" (jaja, sind "nur" Standardfunktionen):
http://dotnet-snippets.de/dns/textdatei-lesen-und-schreiben-string-stringarray-etc-SID818.aspx
Ich füg den Source trotzdem hier nochmal ein:
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 Durchaus nützlich ;)
Vorallem liest man NUR EINMAL die Datei ein und kann sie dann flink weiter verarbeiten.
Vorteilhaft bei kleinen- bis mittelgroßen Datenmengen.
Bei EXTREM GROSSEN ist Die Zeilenweise lesung von vorteil, wenn einem der Ram ausgeht!
Eine Bewertung fänd ich schön ![](../images/smilies/smiley1.gif)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
MFG: BiSoN
Es gibt nur zwei unverr?ckbare Weisheiten:
1. Der Computer n?tzt dem Menschen
2. Die Erde ist eine Scheibe
http://t00ltime.kilu.de/ |