Does anyone know where java gets its default temporary path from
It is read from the java.io.tmpdir property.
Files.createTempFile("test", "test");
essentially calls java.nio.file.TempFileHelper.createTempFile(null, prefix, suffix, attrs); which again calls java.nio.file.TempFileHelper.create(dir, prefix, suffix, false, attrs); . There, if dir is null, it is set to tmpdir , which is declared as follows:
private static final Path tmpdir = Paths.get(doPrivileged(new GetPropertyAction("java.io.tmpdir")));
You can set the property explicitly, as shown in the answer from @Joni. If you do not install it explicitly, the JVM initializes it to the default value for the platform at startup - see also the environment variable for managing java.io.tmpdir?
and how not to find him?
If the java.io.tmpdir property points to an invalid directory, a temporary file cannot be created.
source share