---
title: close()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/filehandle/close()
---

# close()

Disallows further access to the represented file or communications channel and signals end of file on communications channels that permit writing.

## Declaration

```swift
func close() throws
```

## Discussion

Discussion If the file handle object owns its file descriptor, it automatically closes that descriptor when deallocated. If you initialized the file handle object using the init(fileDescriptor:) method, or you initialized it using the init(fileDescriptor:closeOnDealloc:) and passed false for the flag parameter, you can use this method to close the file descriptor; otherwise, you must close the file descriptor yourself. After calling this method, you may still use the file handle object, but you must not attempt to read or write data or use the object to operate on the file descriptor. Attempts to read or write a closed file descriptor raise an exception.

## See Also

### Operating on a file

- [synchronize()](foundation/filehandle/synchronize().md)
- [truncate(atOffset:)](foundation/filehandle/truncate(atoffset:).md)
