| 293 | } |
| 294 | |
| 295 | public static File createTempFile(String prefix, String suffix, File directory) throws IOException { |
| 296 | if (prefix.length() < 3) |
| 297 | throw new IllegalArgumentException("Prefix string too short"); |
| 298 | if (suffix == null) |
| 299 | suffix = ".tmp"; |
| 300 | if (directory == null) { |
| 301 | String tmpDir = System.getProperty("java.io.tmpdir"); |
| 302 | if (tmpDir == null) tmpDir = "/tmp"; |
| 303 | directory = new File(tmpDir); |
| 304 | } |
| 305 | |
| 306 | File f; |
| 307 | do { |
| 308 | long n = System.currentTimeMillis(); |
| 309 | f = new File(directory, prefix + n + suffix); |
| 310 | } while (f.exists()); |
| 311 | |
| 312 | if (!f.createNewFile()) |
| 313 | throw new IOException("Unable to create temporary file"); |
| 314 | |
| 315 | return f; |
| 316 | } |
| 317 | |
| 318 | public static File createTempFile(String prefix, String suffix) throws IOException { |
| 319 | return createTempFile(prefix, suffix, null); |