1 23 24 29 30 package com.sun.appserv.management.util.misc; 31 32 import java.io.File ; 33 import java.io.IOException ; 34 35 36 39 public final class SafeSave 40 { 41 private SafeSave() {} 42 43 private static File 44 formTempName( String baseName ) 45 { 46 return( new File ( baseName + System.currentTimeMillis() + ".temp" ) ); 47 } 48 49 53 public static File 54 getTempFile( File baseFile ) throws IOException 55 { 56 File tempFile = null; 57 58 while ( (tempFile = formTempName( baseFile.toString() ) ).exists() ) 59 { 60 } 61 62 return( tempFile ); 63 } 64 65 70 public static void 71 replaceWithNew( File origFile, File newFile) throws IOException 72 { 73 final File origTemp = getTempFile( origFile ); 74 75 origFile.renameTo( origTemp ); 76 newFile.renameTo( origFile ); 77 origTemp.delete(); 78 } 79 } 80 81 | Popular Tags |