TFileStream(50分)

  • 主题发起人 主题发起人 LeeChange
  • 开始时间 开始时间
L

LeeChange

Unregistered / Unconfirmed
GUEST, unregistred user!
var
FileStream: TFileStream;
begin
FileStream:=TFileStream.Create('1.dat', ...);
.
.
.
end;
1.dat有2M,怎么将前1M的内容从FileStream中截去
 
FileStream.Position:=FileStream.Size div 2
try on it
 
FileStream.Position:=...
FileStream.read(...)
 
用一个临时文件可以吗?
先copy,然后删除该文件,再改名!
 
easy ! Use a Buffer ;

Var FS:TfileStream;
Buf:Pointer;
Begin
GetMem(Buf,YourNewFileSize);
FS:=TFileStream.Create(YourFileName, fmOpenRead);
FS.Position:=YourStartPosition;
FS.Read(Buf^,YourNewFileSize);
FS.Free;
FS:=TFileStream.Create(YourFileName, fmOpenWrite or fmCreate);
FS.Write(Buf^,YourNewFileSize);
FS.Free;
FreeMem(Buf,YourNewFileSize);
End;
 
FileStream.Seek(1024*1024, soFromBeginning);
 
大家的意思都一样,跳指针!
 
const
StartPos=1024*1024;
var
FileStream,fs2: TFileStream;
begin
FileStream:=TFileStream.Create('1.dat', ModeForWrite);
fs2:=TFileStream.Create('1.dat', ModeForRead);
fs2.seek(StartPos);
FileStream.CopyFrom(fs2,fs2.Size-StartPos);
fs2.Free;
FileStream.Truncate;
...
end;
 
多人接受答案了。
 
后退
顶部