[Overview][Constants][Types][Classes][Procedures and functions][Variables] | Reference for unit 'sysutils' (#rtl) |
Create a new file and return a handle to it.
Source position: line 0
function FileCreate( |
const FileName: String |
):THandle; |
const FileName: String; |
Mode: Integer |
):THandle; |
FileCreate creates a new file with name FileName on the disk and returns a file handle which can be used to read or write from the file with the FileRead and FileWrite functions. If a file with name FileName already existed on the disk, it is overwritten.
If an error occurs (e.g. disk full or non-existent path), the function returns -1.
|
Close a file handle. |
|
|
Write data from a buffer to a given filehandle. |
|
|
Open an existing file and return a filehandle |
|
|
Read data from a filehandle in a buffer. |
|
|
Truncate an open file to a given size. |
|
|
Set the current file position on a file handle. |
Program Example37; { This program demonstrates the FileCreate function } Uses sysutils; Var I,J,F : Longint; Begin F:=FileCreate ('test.dat'); If F=-1 then Halt(1); For I:=0 to 100 do FileWrite(F,I,SizeOf(i)); FileClose(f); F:=FileOpen ('test.dat',fmOpenRead); For I:=0 to 100 do begin FileRead (F,J,SizeOF(J)); If J<>I then Writeln ('Mismatch at file position ',I) end; FileSeek(F,0,fsFromBeginning); Randomize; Repeat FileSeek(F,Random(100)*4,fsFromBeginning); FileRead (F,J,SizeOf(J)); Writeln ('Random read : ',j); Until J>80; FileClose(F); F:=FileOpen('test.dat',fmOpenWrite); I:=50*SizeOf(Longint); If FileTruncate(F,I) then Writeln('SuccessFully truncated file to ',I,' bytes.'); FileClose(F); End.
No notes exist for this page yet.