List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:Main.java
public static void delete(File src) { if (src.exists()) { if (!src.delete()) { src.deleteOnExit(); }// w ww . ja v a2 s.c o m } }
From source file:Main.java
public static boolean canWriteTo(File dir) { try {//w ww. ja va2 s.c o m File tmp = new File(dir, "del.me"); tmp.createNewFile(); tmp.deleteOnExit(); tmp.delete(); return true; } catch (Exception ex) { return false; } }
From source file:Main.java
public static void delete(String path) { try {/* w w w. j a va 2s . c om*/ if (path == null) { return; } File file = new File(path); if (!file.delete()) { file.deleteOnExit(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
protected static File createImageFile(Context context, String fileName) throws IOException { ContextWrapper cw = new ContextWrapper(context); // path to /data/data/yourapp/app_data/imageDir File directory = cw.getDir(IMAGE_DIR, Context.MODE_PRIVATE); // Create imageDir File path = new File(directory, fileName + IMAGE_EXT); path.deleteOnExit(); return path;/*from w w w. j av a 2 s. com*/ }
From source file:Main.java
public static File createTempFile(String prefix, String suffix) throws IOException { // this allows use to eaily identify all our dtemp files and delete them, since delete on Exit doesn't really work. File file = File.createTempFile("ohfu-" + prefix, suffix); file.deleteOnExit(); return file;//from www .ja va 2 s . com }
From source file:Main.java
public static String getHardDiskSN(String drive) { String result = ""; try {/*from w w w. j a va 2 s .co m*/ File file = File.createTempFile("realhowto", ".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + drive + "\")\n" + "Wscript.Echo objDrive.SerialNumber"; // see note fw.write(vbs); fw.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch (Exception e) { e.printStackTrace(); } return result.trim(); }
From source file:com.javacreed.examples.io.RafHelperTest.java
private static File createSampleFile(final String data) throws IOException { final File file = File.createTempFile("RafHelper", "test"); file.deleteOnExit(); FileUtils.write(file, data, "UTF-8"); return file;//from www.j a va 2s . c om }
From source file:com.googlecode.fannj.FannTest.java
public static File createTemp(File src) throws IOException { File temp = File.createTempFile("fannj_", ".net"); temp.deleteOnExit(); FileUtils.copyFile(src, temp);/* ww w .jav a 2 s .co m*/ return temp; }
From source file:Main.java
public static String getMotherboardSN() { String result = ""; try {/*from w ww .java2 s . co m*/ File file = File.createTempFile("realhowto", ".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + " exit for ' do the first cpu only! \n" + "Next \n"; fw.write(vbs); fw.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch (Exception e) { e.printStackTrace(); } return result.trim(); }
From source file:hu.bme.mit.incqueryd.engine.util.EObjectSerializer.java
public static File createTempFile() throws IOException { final File tempFile = File.createTempFile("temp-", ".json"); tempFile.deleteOnExit(); return tempFile; }