public static File writeStringToTempFile ( String prefix , String suffix , String data ) throws IOException { File testFile = File . createTempFile ( prefix , suffix ) ; BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( testFile . getAbsoluteFile ( ) , false ) , DataUtilDefaults . charSet ) ) ; writer . write ( data ) ; writer . flush ( ) ; writer . close ( ) ; return testFile ; }
This method writes all data from a string to a temp file . The file will be automatically deleted on JVM shutdown .