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

# synchronizeFile()

Causes all in-memory data and attributes of the file represented by the handle to write to permanent storage.

## Declaration

```swift
func synchronizeFile()
```

## Discussion

Discussion Programs that require the file to always be in a known state should call this method. An invocation of this method doesn’t return until memory is flushed. important: This method raises fileHandleOperationException if called on a file handle representing a pipe or socket, if the file descriptor is closed, or if the operation failed.

## See Also

### Deprecated

- [readDataToEndOfFile()](foundation/filehandle/readdatatoendoffile().md)
- [readData(ofLength:)](foundation/filehandle/readdata(oflength:).md)
- [write(_:)](foundation/filehandle/write(_:).md)
- [offsetInFile](foundation/filehandle/offsetinfile.md)
- [seekToEndOfFile()](foundation/filehandle/seektoendoffile().md)
- [seek(toFileOffset:)](foundation/filehandle/seek(tofileoffset:).md)
- [closeFile()](foundation/filehandle/closefile().md)
- [truncateFile(atOffset:)](foundation/filehandle/truncatefile(atoffset:).md)
- [NSFileHandleNotificationMonitorModes](foundation/nsfilehandlenotificationmonitormodes.md)
