---
title: "CFWriteStreamCreateWithFile(_:_:)"
framework: corefoundation
role: symbol
role_heading: Function
path: "corefoundation/cfwritestreamcreatewithfile(_:_:)"
---

# CFWriteStreamCreateWithFile(_:_:)

Creates a writable stream for a file.

## Declaration

```swift
func CFWriteStreamCreateWithFile(_ alloc: CFAllocator!, _ fileURL: CFURL!) -> CFWriteStream!
```

## Parameters

- `alloc`: The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.
- `fileURL`: The URL of the file to which to write. The URL must use a file scheme.

## Return Value

Return Value The new write stream, or NULL on failure. Ownership follows the The Create Rule.

## Discussion

Discussion The stream overwrites an existing file unless you set the kCFStreamPropertyAppendToFile to kCFBooleanTrue with CFWriteStreamSetProperty(_:_:_:), in which case the stream appends data to the file. You must open the stream, using CFWriteStreamOpen(_:), before writing to it.

## See Also

### Creating a Write Stream

- [CFWriteStreamCreateWithAllocatedBuffers(_:_:)](corefoundation/cfwritestreamcreatewithallocatedbuffers(_:_:).md)
- [CFWriteStreamCreateWithBuffer(_:_:_:)](corefoundation/cfwritestreamcreatewithbuffer(_:_:_:).md)
