VB - كيف قرأت وكتابة ملف ثنائي؟
-
11-09-2019 - |
سؤال
كيف يمكنني قراءة صفيف بايت الخام من أي ملف ...
Dim bytes() as Byte
.. ثم اكتب صفيف البايت مرة أخرى إلى ملف جديد؟
أحتاجها كصفيف بايت للقيام ببعض المعالجة بينهما.
أنا الآن باستخدام:
ليقرأ
Dim fInfo As New FileInfo(dataPath)
Dim numBytes As Long = fInfo.Length
Dim fsAs New FileStream(dataPath, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CInt(numBytes))
br.Close()
fs.Close()
لأكتب
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(outpath, System.IO.FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
المحلول
Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)
نصائح أخرى
System.IO.File.ReadAllBytes("myfile.txt")
جرب هذا:-
Dim bytes() as Byte
bytes = File.ReadAllBytes(fileName)
'' # Do stuff to the array
File.WriteAllBytes(otherFileName, bytes)
لا تنتمي إلى StackOverflow