将图片以string读出来然后存入新的文件,新文件是损坏的,求解?该如何解决
将图片以string读出来然后存入新的文件,新文件是损坏的,求解?
Private Sub Command1_Click()
writeFile (GetFile("c:/3.txt"))
End Sub
Function GetFile(strFileName As String) As String
Dim strFile As String
nFile = FreeFile
Open strFileName For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile
GetFile = strFile
End Function
Function writeFile(aPostBody As String)
Open "c:\4.txt" For Binary As #1
Put #1, , aPostBody
Close #1
End Function
------解决方案--------------------
方法错误,应该改成这样:
Private Sub Command1_Click()
writeFile (GetFile("c:/3.txt"))
End Sub
Function GetFile(strFileName As String) As String
Dim strFile As String
nFile = FreeFile
Open strFileName For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile
GetFile = strFile
End Function
Function writeFile(aPostBody As String)
Open "c:\4.txt" For Binary As #1
Put #1, , aPostBody
Close #1
End Function
------解决方案--------------------
方法错误,应该改成这样:
- VB code
option Explicit Function GetFile(ByVal strFileName As String) As String Dim strFile As String, bFile() As Byte Dim nFile As Long nFile = FreeFile Open strFileName For Binary As #nFile ReDim bFile(LOF(nFile) - 1) Get #nFile, , bFile strFile = StrConv(bFile, vbUnicode) Debug.Print strFile Close #nFile GetFile = strFile End Function Function writeFile(ByVal aPostBody As String) Open "c:\4.txt" For Binary As #1 Put #1, , aPostBody Close #1 End Function Private Sub Command1_Click() writeFile (GetFile("c:/13-1.log")) End Sub
------解决方案--------------------
告诉你一个不幸的消息,下面这一堆程序等同于VB的FileCopy。
- VB code
Option Explicit Function GetFile(ByVal strFileName As String) As Byte() Dim strFile As String Dim nFile As Long nFile = FreeFile Open strFileName For Binary As #nFile ReDim GetFile(LOF(nFile) - 1) Get #nFile, , GetFile Debug.Print strFile Close #nFile End Function Function writeFile(ByRef aPostBody() As Byte) Open "c:\4.jpg" For Binary As #1 Put #1, , aPostBody Close #1 End Function Private Sub Command1_Click() writeFile GetFile("C:\3.jpg") End Sub
------解决方案--------------------