var
fs:TFileStream;
buf:array[0..1024]of byte;fs:=TFileStream.Create('file',frReadWrite);
fs.Read(buf,sizeof(buf));
fs:TFileStream;
buf:array[0..1024]of byte;fs:=TFileStream.Create('file',frReadWrite);
fs.Read(buf,sizeof(buf));
解决方案 »
- 关于使用alphacontrol不美化动态创建子窗体的问题
- delphi绝对路经改相对路经问题
- 长整型取模计算
- 关于twindowsmediaplayer的问题 急
- 使用shelltreeview出错(在线等待)
- RM3,打印预览的导出EXCEL,怎么导出来的少了不少网格?很难看?导成HTM就正常,怎么回事??
- 高分求救关于保存数据到数据库中的问题!
- 请问各位高手:hHwnd := FindWindow('#32563', nil) 中的#32563是怎么得来的?
- 如何从项目或项目组中删除单元?
- 大四了,找工作了,悔不当初啊!
- 请教各位高人,在dbgrid中如何把焦点移到前一单元格.
- 小妹?^_^?捉虫:在程序中gotokey方法上去作用,是怎么回事啊?
var
SrcFile, DestFile: File;
BytesRead, BytesWritten, TotalRead: Integer;
Buffer: array[1..500] of byte;
FSize: Integer;
begin
{ Assign both the source and destination files to their
respective file variables }
AssignFile(SrcFile, 'srcfile.tst');
AssignFile(DestFile, 'destfile.tst');
// Open the source file for read access.
Reset(SrcFile, 1);
try
// Open destination file for write access.
Rewrite(DestFile, 1);
try
{ Encapsulate this into a try..except so that we can erase the file if
an error occurs. }
try
// Initialize total bytes read to zero.
TotalRead := 0;
// Obtain the filesize of the source file
FSize := FileSize(SrcFile);
{ Read SizeOf(Buffer) bytes from the source file
and add these bytes to the destination file. Repeat this
process until all bytes have been read from the source
file. A progress bar is provided to show the progress of the
copy operation. }
repeat
BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
if BytesRead > 0 then
begin
BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
if BytesRead <> BytesWritten then
raise Exception.Create('Error copying file')
else begin
TotalRead := TotalRead + BytesRead;
prbCopy.Position := Trunc(TotalRead / Fsize) * 100;
prbCopy.Update;
end;
end
until BytesRead = 0;
except
{ On an exception, erase the destination file as it may be
corrupt. Then re-raise the exception. }
Erase(DestFile);
raise;
end;
finally
CloseFile(DestFile); // Close the destination file.
end;
finally
CloseFile(SrcFile); // Close the source file.
end;
end;
a: TFileStream;a := TFileStream.Create(FileName, fmOpenRead);
还是看看Help中关于TFileStream,一看就明白了。
ReadFile和WriteFile