If you are using JUnit, there is a TemporaryFolder . Files are deleted after the test. Example shown on page:
public static class HasTempFolder { @Rule public TemporaryFolder folder= new TemporaryFolder(); @Test public void testUsingTempFolder() throws IOException { File createdFile= folder.newFile("myfile.txt"); File createdFolder= folder.newFolder("subfolder");
However, I also used it to test the read and write capabilities of the Android class, for example:
[...] pw = new PrintWriter(folder.getAbsolutePath() + '/' + filename); pw.println(data);
comodoro
source share