# Close
{: .no_toc }

Concludes input/output (I/O) to a file opened using the **Open** statement.

Syntax: 

- **Close** [[ **#** ] *filenumber1* ] [ **,** [ **#** ] *filenumber2* ] *. . .*  
  The *filenumber* is any valid file number, given as an expression evaluating to an integer. The file numbers do not have to be constant. The **#** prefixes are optional.
  
- **Close**  
  When the *filenumber* list is omitted, all active files opened by the **Open** statement are closed.

> [!WARNING]
>
> The parameterless form should be used only when shutting down/exiting the program, since it closes *all* open files that were opened elsewhere in the program.

When files opened for **Output** or **Append** are closed, the final buffer of output is written to the operating system buffer for that file. All buffer space associated with the closed file is released.

When the **Close** statement is executed, the association of a file with its file number ends.

### Example

This example uses the **Close** statement to close the three files opened  for **Output**.

```tb check_build
Dim I%, FileName$, FileNumber%(1 To 3)
For I = 1 To 3             ' Loop 3 times
   FileName = "TEST" & I   ' Create file name
   FileNumber(I) = FreeFile()
   Open FileName For Output As #FileNumber(I)   ' Open file
   Print #FileNumber(I), "This is a test."      ' Write string to file
Next I
Close #FileNumber(1), #FileNumber(2), #FileNumber(3)  ' Close the 3 open files.
```

### See Also

- [Open](/tB/Core/Open.md) statement
- [FreeFile](/tB/Modules/FileSystem/index.md) function
