---
schema_version: "1"
id: ac3360a28c4aaac9162564f8aab5696859569bb802802fe8c941ceea0bc3664b
title: To Write a File Using the File Connector
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/file-connector/latest/file-write.md
canonical_url: https://docs.mulesoft.com/file-connector/latest/file-write
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d194ab98dd1d57ac9108564252572a10209659c859b9444b2956e6df5e466a6d
description: MuleSoft Documentation Site
release: "1.5"
latest: true
---
---
product: File Connector
version: 1.5
is-latest-version: true
keywords: file, connector, write
---

# To Write a File Using the File Connector

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

A Write operation is available to the File, FTP, and SFTP connectors. For these connectors, the
operation writes content into the given path on demand. It supports common use cases described
below.

## Embedded DataWeave Transformations

By default, the connector writes whatever is in the message payload:

Example: File Connector

```xml
<file:write path="output.csv" />
```

However, if the payload is a different format (for example, not CSV) and you need to transform it
before writing it, what do you do? If you place a Transform component before the Write operation,
the message payload changes and that impacts the operation that is placed after the Write operation.

To avoid this undesired impact, you can place the transformation inside the Write operation to
generate content that will be written without producing a side effect on the message in transit.

The next example uses the File connector to write the content:

Example: Transformation within a File Write Operation

```xml
<file:write path="output.csv">
  <file:content>#[%dw 2.0
                  output application/csv
                  ---
                  payload.customers.email
                ]
  </file:content>
</file:write>
```

## Writing into Directories

If any of the `a`, `b`, or `c` directories in the example below do not exist, the Write operation
will fail by default. However, if you set the `createParentDirectories` to `true`, the connector
will automatically create any missing directories.

Example: File Connector writes to a Directory

```xml
<file:write path="a/b/c/myFile.txt" />
```

## Write to Existing Files

When writing content to a file, set **Write Mode** to any of the following modes:

- **OVERWRITE (Default)**  
  If the file exists, overwrite it completely.

- **APPEND**  
  If the file exists, add its content to the end of an existing file.

- **CREATE\_NEW**  
  Create a new file. If the file already exists, then you receive an error.

## Locks

The **Write** operation supports locking similar to the **Read** operation. The main difference is
that the lock releases automatically after the **Write** operation finishes. Set **Lock** to any of
the following modes:

- **TRUE**

- **FALSE (Default)**
