You can use org.junit.rules.TemporaryFolder from the JUnit package:
The TemporaryFolder Rule allows creation of files and folders that are guaranteed to be deleted when the test method finishes (whether it passes or fails):
Example:
final TemporaryFolder testFolder = new TemporaryFolder();
testFolder.create();
final Path filePath = testFolder.newFile("input.txt").toPath();
final Path dirPath = testFolder.newFolder("subfolder").toPath();
Alternatively quit the .toPath() part:
final File filePath = testFolder.newFile("input.txt");