# 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
```al
 File.Close()
```
> NOTE
> This method can be invoked without specifying the data type name.
## Parameters
File
Type: file-data-type
An instance of the file-data-type 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 file-writemode-method allows the file to be open for writing. The file-open-method opens the file, the file-writemode-method 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.
```al
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;
```
## Related information
file-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-close-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-close-method/
