---
Product: Aspose.PDF
Platform: java
Page Type: docs
Canonical URL: https://docs.aspose.org/pdf/java/developer-guide/io
---

# I/O Operations

File and stream I/O in Aspose.PDF FOSS for Java — file paths, streams, and in-memory pipelines.

## I/O Patterns

Aspose.PDF FOSS for Java consistently accepts both file paths and Java streams as
input and output in all major APIs, including `Document`, `PdfFileEditor`, and all
facade classes.

## Document I/O

The `Document` class accepts a file path string or an `InputStream` in its constructor.
The `save()` method accepts a file path string or an `OutputStream`.

```java
// File path input
try (Document doc = new Document("input.pdf")) {
    doc.save("output.pdf");
}

// Stream input/output
try (Document doc = new Document(inputStream)) {
    doc.save(outputStream);
}
```

Both constructors load the entire document into memory. For large documents, ensure
sufficient heap space or consider using `PdfFileEditor.setUseDiskBuffer(true)`.

## PdfFileEditor Stream Support

`PdfFileEditor` operations accept both file path strings and Java `InputStream`/`OutputStream`
objects:

```java
PdfFileEditor editor = new PdfFileEditor();
// All operations support both file paths and streams
editor.concatenate(new InputStream[]{s1, s2}, outputStream);
editor.extract(inputStream, 1, 3, outputStream);
```

## In-Memory Pipelines

For in-memory pipelines that avoid temporary files, use `ByteArrayOutputStream` to
capture document output, then wrap with `ByteArrayInputStream` for downstream processing:

```java
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (Document doc = new Document()) {
    doc.getPages().add();
    doc.save(buffer);
}
byte[] pdfBytes = buffer.toByteArray();
// Pass pdfBytes downstream — no temp file needed
ByteArrayInputStream next = new ByteArrayInputStream(pdfBytes);
```

## Facade I/O

All facade classes (e.g. `PdfAnnotationEditor`, `PdfContentEditor`, `PdfFileSecurity`)
follow the same bind-operate-save pattern and accept file paths, streams, or a `Document`
object via their `bindPdf()` method.

## See Also

- [Aspose.PDF for Java — Enterprise Documentation](https://docs.aspose.com/pdf/java/)