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