---
title: "truncateFile(atOffset:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filehandle/truncatefile(atoffset:)"
---

# truncateFile(atOffset:)

Truncates or extends the file represented by the file handle to a specified offset within the file and puts the file pointer at that position.

## Declaration

```swift
func truncateFile(atOffset offset: UInt64)
```

## Parameters

- `offset`: The offset within the file that marks the new end of the file.

## Discussion

Discussion If the file is extended (if offset is beyond the current end of file), the added characters are null bytes. 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)
- [synchronizeFile()](foundation/filehandle/synchronizefile().md)
- [NSFileHandleNotificationMonitorModes](foundation/nsfilehandlenotificationmonitormodes.md)
