Index: tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java	(revision 1703352)
+++ tika-core/src/main/java/org/apache/tika/io/TemporaryResources.java	(revision )
@@ -19,6 +19,8 @@
 import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.LinkedList;
 
 import org.apache.tika.exception.TikaException;
@@ -36,43 +38,65 @@
     /**
      * Tracked resources in LIFO order.
      */
-    private final LinkedList<Closeable> resources = new LinkedList<Closeable>();
+    private final LinkedList<Closeable> resources = new LinkedList<>();
 
     /**
      * Directory for temporary files, <code>null</code> for the system default.
      */
-    private File tmp = null;
+    private Path tempFileDir = null;
 
     /**
      * Sets the directory to be used for the temporary files created by
-     * the {@link #createTemporaryFile()} method.
+     * the {@link #createTempFile()} method.
      *
-     * @param tmp temporary file directory,
+     * @param tempFileDir temporary file directory,
-     *            or <code>null</code> for the system default
+     *                    or <code>null</code> for the system default
      */
-    public void setTemporaryFileDirectory(File tmp) {
-        this.tmp = tmp;
+    public void setTemporaryFileDirectory(Path tempFileDir) {
+        this.tempFileDir = tempFileDir;
     }
 
     /**
-     * Creates and returns a temporary file that will automatically be
-     * deleted when the {@link #close()} method is called.
+     * Sets the directory to be used for the temporary files created by
+     * the {@link #createTempFile()} method.
      *
-     * @return Created temporary file that'll be deleted after closing
+     * @param tempFileDir temporary file directory,
+     *                    or <code>null</code> for the system default
+     * @see #setTemporaryFileDirectory(Path)
+     */
+    public void setTemporaryFileDirectory(File tempFileDir) {
+        this.tempFileDir = tempFileDir == null ? null : tempFileDir.toPath();
+    }
+
+    /**
+     * Creates a temporary file that will automatically be deleted when
+     * the {@link #close()} method is called, returning its path.
+     *
+     * @return Path to created temporary file that will be deleted after closing
      * @throws IOException
      */
-    public File createTemporaryFile() throws IOException {
-        final File file = File.createTempFile("apache-tika-", ".tmp", tmp);
+    public Path createTempFile() throws IOException {
+        final Path path = tempFileDir == null
+                ? Files.createTempFile("apache-tika-", ".tmp")
+                : Files.createTempFile(tempFileDir, "apache-tika-", ".tmp");
         addResource(new Closeable() {
             public void close() throws IOException {
-                if (!file.delete()) {
-                    throw new IOException(
-                            "Could not delete temporary file "
-                            + file.getPath());
+                Files.delete(path);
-                }
+            }
-            }
         });
-        return file;
+        return path;
+    }
+
+    /**
+     * Creates and returns a temporary file that will automatically be
+     * deleted when the {@link #close()} method is called.
+     *
+     * @return Created temporary file that'll be deleted after closing
+     * @throws IOException
+     * @see #createTempFile()
+     */
+    public File createTemporaryFile() throws IOException {
+        return createTempFile().toFile();
     }
 
     /**
Index: tika-core/src/test/java/org/apache/tika/io/TemporaryResourcesTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tika-core/src/test/java/org/apache/tika/io/TemporaryResourcesTest.java	(revision )
+++ tika-core/src/test/java/org/apache/tika/io/TemporaryResourcesTest.java	(revision )
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.io;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.Assert.assertTrue;
+
+public class TemporaryResourcesTest {
+
+    @Test
+    public void testFileDeletion() throws IOException {
+        Path tempFile;
+        try (TemporaryResources tempResources = new TemporaryResources()) {
+            tempFile = tempResources.createTempFile();
+            assertTrue("Temp file should exist while TempResources is used", Files.exists(tempFile));
+        }
+        assertTrue("Temp file should not exist after TempResources is closed", Files.notExists(tempFile));
+    }
+
+}
