編集

次の方法で共有


File.Close() Method

Version: Available or changed with runtime version 1.0.

Closes a file that has been opened by the OPEN method (File).

Note

This method is supported only in Business Central on-premises.

Syntax

 File.Close()

Note

This method can be invoked without specifying the data type name.

Parameters

File
 Type: File
An instance of the File data type.

Remarks

If the file is not open, a run-time error will occur.

Example

The following example determines whether the specified file exists. If it exists, the WriteMode Method (File) allows the file to be open for writing. The Open Method (File) opens the file, the Write Method (File) writes the text “Hello World” to the file, and then the Close method closes the file. If the file does not exist, an error message is displayed. This example assumes that you have created the following file C:\TestFolder\TestFile2.txt.

var
    FileName: Text;
    TestFile: File;
begin
    FileName := 'C:\TestFolder\TestFile2.txt';  
    if Exists(FileName) then begin  
      TestFile.WriteMode(true);  
      TestFile.Open(FileName);  
      TestFile.Write('Hello World');  
      TestFile.Close;  
    end else  
    Message('%1 does not exist.', FileName);  
end;

File Data Type
Get Started with AL
Developing Extensions