diff --git a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java
index 3df492b430963d2258bb98cfb5173f5e52a625c2..641bd5e236060bd51358e61b539565b7835742d6 100644
--- a/src/main/java/teetime/stage/io/ByteArrayFileWriter.java
+++ b/src/main/java/teetime/stage/io/ByteArrayFileWriter.java
@@ -11,11 +11,13 @@ import com.google.common.io.Files;
 public class ByteArrayFileWriter extends ConsumerStage<byte[]> {
 
 	private final File file;
+	private FileOutputStream fo;
 
 	public ByteArrayFileWriter(final File file) {
 		this.file = file;
 		try {
 			Files.touch(file);
+			fo = new FileOutputStream(this.file);
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
@@ -23,13 +25,20 @@ public class ByteArrayFileWriter extends ConsumerStage<byte[]> {
 
 	@Override
 	protected void execute(final byte[] element) {
-		FileOutputStream fo;
+
 		try {
-			fo = new FileOutputStream(this.file);
 			fo.write(element);
-			fo.close();
 		} catch (Exception e) {
 			throw new IllegalStateException(e);
 		}
 	}
+
+	@Override
+	public void onTerminating() {
+		try {
+			fo.close();
+		} catch (IOException e) {
+			throw new IllegalStateException(e);
+		}
+	}
 }