This is not a tag line!
Posts tagged gotcha
Beware of File.createTempFile
Sep 4th
By default, File.createTempFile (in Java, of course) creates a temporary file in the directory identified by the system property java.io.tmpdir. The problem is that on OS X, that directory can be quite weird. For example, on my system, it currently is:
scala> System.getProperties().getProperty("java.io.tmpdir")
res0: java.lang.String = /var/folders/ya/yaNATrKPGFu2HuSOWxSIu++++TI/-Tmp-/
Notice the ++++ in one of the directory names? Well, these little characters can later cause headaches! The reason, you ask? Simple, if that temporary file name is ever used in a URL, then those plus signs will be interpreted as spaces and whatever code is using a URL to find your temporary file will not find it! So beware!
Possible solutions include passing -Djava.io.tmpdir="whatever" when you launch your Java process, or use the createTempFile(String prefix, String suffix, File directory) version of File.createTempFile and pass it a directory that doesn’t contain an + sign in its name!
