---
title: "Save a Document in Java"
---


```

## Purpose Summary

This page explains how to save a document in different formats using Aspose.Words.

```

Most of the tasks you need to perform with Aspose.Words involve saving a document. To save a document Aspose.Words provides the [save()](https://reference.aspose.com/words/java/com.aspose.words/document/#save-java.lang.String) method of the [Document](https://reference.aspose.com/words/java/com.aspose.words/document/) class. The document can be saved in any save format supported by Aspose.Words. For the list of all supported save formats, see the [SaveFormat](https://reference.aspose.com/words/java/com.aspose.words/saveformat/) enumeration.

## Save to a File {#save-a-document-to-a-file}

Simply use the [save()](https://reference.aspose.com/words/java/com.aspose.words/document/#save-java.lang.String) method with a file name. Aspose.Words will determine the save format from the file extension that you specify.

The following code example shows how to load and save a document to a file:

```java
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Document.doc");

doc.save(getArtifactsDir() + "BaseConversions.DocToDocx.docx");
```

```

You can download the template file of this example from [Aspose.Words GitHub](https://github.com/aspose-words/Aspose.Words-for-Java/blob/master/Examples/Data/Document.doc).

```

## Save to a Stream {#save-a-document-to-a-stream}

Pass a stream object to the [save()](https://reference.aspose.com/words/java/com.aspose.words/document/#save-java.io.OutputStream-com.aspose.words.SaveOptions) method. It's necessary to specify the save format explicitly when saving to a stream.

The following code example shows how to load and save a document to a stream:

```java
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
// Read only access is enough for Aspose.Words to load a document.
FileInputStream stream = new FileInputStream(getMyDir() + "Document.docx");

Document doc = new Document(stream);
// You can close the stream now, it is no longer needed because the document is in memory.
stream.close();

// ... do something with the document.

// Convert the document to a different format and save to stream.
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
doc.save(dstStream, SaveFormat.RTF);
```

You can download the template file of this example from [Aspose.Words GitHub](https://github.com/aspose-words/Aspose.Words-for-Java/blob/master/Examples/Data/Document.doc).

## Save to PCL {#save-a-document-to-pcl}

Aspose.Words supports saving a document into PCL (Printer Command Language). Aspose.Words can save documents into PCL 6 (PCL 6 Enhanced or PCL XL) format. The `PclSaveOptions` class can be used to specify additional options when saving a document into the PCL format.

The following code example shows how to save a document to PCL using save options:

```java
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Rendering.docx");

PclSaveOptions saveOptions = new PclSaveOptions();
saveOptions.setSaveFormat(SaveFormat.PCL);
saveOptions.setRasterizeTransformedElements(false);

doc.save(getArtifactsDir() + "WorkingWithPclSaveOptions.RasterizeTransformedElements.pcl", saveOptions);
```
