# File I/O Integration | Sentry for Java

Capturing transactions requires that you first [set up tracing](https://docs.sentry.io/platforms/java/tracing.md) if you haven't already.

Sentry file I/O integration provides the `SentryFileInputStream`/`SentryFileOutputStream` and `SentryFileReader`/`SentryFileWriter`, which create a span for each File read/write operation.

### [Install](https://docs.sentry.io/platforms/java/tracing/instrumentation/file-io.md#install)

The file I/O Integration is available under the core Java SDK package.

```xml
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry</artifactId>
    <version>8.23.0</version>
</dependency>
```

For other dependency managers, see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry).

### [Configure](https://docs.sentry.io/platforms/java/tracing/instrumentation/file-io.md#configure)

To instrument `FileInputStream`/`FileOutputStream` the SDK provides drop-in replacements such as `SentryFileInputStream`/`SentryFileOutputStream`.

*Old*:

```java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

File file1 = new File("file1.txt");
File file2 = new File("file2.txt");
try (FileInputStream fis = new FileInputStream(file1)) {
  byte[] buffer = new byte[1024];
  try (FileOutputStream fos = new FileOutputStream(file2)) {
    int read;
    while (true) {
      read = fis.read(buffer);
      if (read == -1) {
        break;
      }
      fos.write(buffer, 0, read);
    }
  }
}
```

*New*:

```java
import io.sentry.instrumentation.file.SentryFileInputStream;
import io.sentry.instrumentation.file.SentryFileOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

File file1 = new File("file1.txt");
File file2 = new File("file2.txt");
try (FileInputStream fis = new SentryFileInputStream(file1)) {
  byte[] buffer = new byte[1024];
  try (FileOutputStream fos = new SentryFileOutputStream(file2)) {
    int read;
    while (true) {
      read = fis.read(buffer);
      if (read == -1) {
        break;
      }
      fos.write(buffer, 0, read);
    }
  }
}
```

Similarly, `FileReader`/`FileWriter` can be instrumented through `SentryFileReader`/`SentryFileWriter`:

*Old*:

```java
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

File file1 = new File("file1.txt");
File file2 = new File("file2.txt");
try (FileReader reader = new FileReader(file1)) {
  char[] buffer = new char[1024];
  try (FileWriter writer = new FileWriter(file2, true)) {
    int read;
    while (true) {
      read = reader.read(buffer, 0, buffer.length);
      if (read == -1) {
        break;
      }
      writer.write(buffer, 0, buffer.length);
    }
    writer.flush();
  }
}
```

*New*:

```java
import io.sentry.instrumentation.file.SentryFileReader;
import io.sentry.instrumentation.file.SentryFileWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

File file1 = new File("file1.txt");
File file2 = new File("file2.txt");
try (FileReader reader = new SentryFileReader(file1)) {
  char[] buffer = new char[1024];
  try (FileWriter writer = new SentryFileWriter(file2, true)) {
    int read;
    while (true) {
      read = reader.read(buffer, 0, buffer.length);
      if (read == -1) {
        break;
      }
      writer.write(buffer, 0, buffer.length);
    }
    writer.flush();
  }
}
```
