9

I need to demo a xml based data interchange system. It is demoed offline on a trusted computer at school. The application will get database later but just for this presentation I only need to show the layout, opening and saving of xml-files and how the table gets data from the xml.

So, what would be the best location to let the web app create the xml files temporarily so I can showcase this app? I'm using Eclipse and Tomcat.

As mentioned, security is not an issue at all, since this version is NOT going to be online. Also, it's ok if the files get erased each time the application is run.

They need to exist only for the duration of the presentation where the application is run once. So, I'm clueless what would be the best location and how to get the path to such location not depending on the computer used.

Thank you.

Steve Waters
  • 3,348
  • 9
  • 54
  • 94

4 Answers4

16

Use the property java.io.tmpdir to get the tomcat temp folder and save your files there. That will be a good place to temporarily keep them in. So you can define it as follows:

public static final String TMP_DIR = System.getProperty("java.io.tmpdir")
Omoro
  • 972
  • 11
  • 22
9

Either use the property java.io.tmpdir as indicated or use the servlet context attribute javax.servlet.context.tempdir defined in the specification. For tomcat that attribute can be changed by the workDir attribute on the context.

You can use that attribute by a call to servletContext.getAttribute("javax.servlet.context.tempdir")

See tomcat documentation for detail.

Cédric Couralet
  • 4,913
  • 1
  • 21
  • 21
3

Old question, but if there is for creating temp file why not use File.createTempFile function?

Example:

File temp = File.createTempFile("real",".howto");
temp.deleteOnExit();
oak
  • 2,898
  • 2
  • 32
  • 65
-3

You can use this method to get temp file location according to your Operating System

public static String getSystemFileLocation()
{
    File tmpFile = null;
    String fileLocation="/tmp/";
    if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") == 0) {
        tmpFile=new File("c:\\temp");
        if(tmpFile.exists()) {
            fileLocation="c:\\temp\\";
        }
        else {
            tmpFile.mkdir();
            fileLocation="c:\\temp\\";
        }
    }
    else if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") == -1) {
        fileLocation="/tmp/";   
    }
    return fileLocation;
}
Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
rohit
  • 37
  • 1
  • 5