Is there a standard place to write temporary files needed for servlets?

John Zukowski

Prior to the Servlets 2.2 API, there was no standard location. The 2.2 API adds the javax.servlet.context.tmpdir attribute to the servlet context that defines where to write something:

File directory = (File)getServletContext().getAttribute("javax.servlet.context.tmpdir");
File file = File.createTempFile("prefix", ".tmp", directory);
FileWriter out = new FileWriter(file);