我用二进制方式复制文件
Dim Bit As Byte
Open "d:\maplog.txt" For Binary As #1
Open "d:\maplog1.txt" For Binary As #2
While Not EOF(1)
Get 1, , Bit
Put 2, , Bit
Wend
Close 1
Close 2
为什么最后复制出来的文件,最后总是多写一个字节,值为0
我用UE查看二进制,确实是最后多了一个字节,请问这是怎么回事?
Dim Bit As Byte
Open "d:\maplog.txt" For Binary As #1
Open "d:\maplog1.txt" For Binary As #2
While Not EOF(1)
Get 1, , Bit
Put 2, , Bit
Wend
Close 1
Close 2
为什么最后复制出来的文件,最后总是多写一个字节,值为0
我用UE查看二进制,确实是最后多了一个字节,请问这是怎么回事?
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long如果文件内容已经在数组里面可以用
ADO里面的Stream 或者 FSO里面的TextStream来操作
Dim Bit() As Byte
Dim lByte As Long
Open "\1.txt" For Binary As #1
Open "\2.txt" For Binary As #2
lByte = LOF(1)
ReDim Bit(lByte - 1)
Get #1, , Bit()
Put #2, , Bit()
Close #1
Close #2
End Sub
Open "d:\maplog.txt" For Binary As #1
Open "d:\maplog1.txt" For Binary As #2
Do
Get #1, , Bit
if EOF(1) then exit do
Put #2, , Bit
Loop
Close #1
Close #2不要使用
while (条件)
更不要使用
while (组合条件)
要使用
while (1) {
if (条件1) break;
//...
if (条件2) continue;
//...
if (条件3) return;
//...
}
因为前两种写法在语言表达意思的层面上有二义性,只有第三种才忠实反映了程序流的实际情况。
典型如:
下面两段的语义都是当文件未结束时读字符
whlie (!feof(f)) {
a=fgetc(f);
//...
b=fgetc(f);//可能此时已经feof了!
//...
}
而这样写就没有问题:
whlie (1) {
a=fgetc(f);
if (feof(f)) break;
//...
b=fgetc(f);
if (feof(f)) break;
//...
}
类似的例子还可以举很多。
Dim Bit As Byte
Dim n As Long
Open "d:\maplog.txt" For Binary As #1
Open "d:\maplog.txt" For Binary As #2
n = LOF(1)
While Loc(1) < n
Get 1, , Bit
Put 2, , Bit
Wend
Close 1
Close 2
Private Sub Command1_Click()
Dim Bit As Byte
Open "c:\1.txt" For Binary As #1
Open "c:\2.txt" For Binary As #2
While Not EOF(1)
Get 1, , Bit
Put 2, , Bit
MsgBox EOF(1) & "|" & Loc(1)
Wend
Close 1
Close 2
End Sub
你会发现无法解释会出现 Fasle|5 这种情况,因为压根只有0-4,没有5,get语句怎么可能通过的呢,get出现的是什么呢???