1 16 package org.apache.poi.util; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 import java.util.Random ; 21 22 27 public class TempFile 28 { 29 static File dir; 30 static Random rnd = new Random (); 31 32 39 public static File createTempFile(String prefix, String suffix) throws IOException 40 { 41 if (dir == null) 42 { 43 dir = new File (System.getProperty("java.io.tmpdir"), "poifiles"); 44 dir.mkdir(); 45 if (System.getProperty("poi.keep.tmp.files") == null) 46 dir.deleteOnExit(); 47 } 48 49 File newFile = new File (dir, prefix + rnd.nextInt() + suffix); 50 if (System.getProperty("poi.keep.tmp.files") == null) 51 newFile.deleteOnExit(); 52 return newFile; 53 } 54 55 56 57 } 58 | Popular Tags |