public static File writeStringToTempFileNoExceptions(String contents, String path, String encoding) {
		OutputStream writer = null;
		File tmp = null;
		try{
			tmp = File.createTempFile(path,".tmp");
			if (path.endsWith(".gz")) {
				writer = new GZIPOutputStream(new FileOutputStream(tmp));
			} else {
				writer = new BufferedOutputStream(new FileOutputStream(tmp));
			}
			writer.write(contents.getBytes(encoding));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(writer != null){ closeIgnoringExceptions(writer); }
		}
		return tmp;
	}
public static File writeStringToTempFileNoExceptions ( String contents , String path , String encoding ) { OutputStream writer = null ; File tmp = null ; try { tmp = File . createTempFile ( path , ".tmp" ) ; if ( path . endsWith ( ".gz" ) ) { writer = new GZIPOutputStream ( new FileOutputStream ( tmp ) ) ; } else { writer = new BufferedOutputStream ( new FileOutputStream ( tmp ) ) ; } writer . write ( contents . getBytes ( encoding ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { if ( writer != null ) { closeIgnoringExceptions ( writer ) ; } } return tmp ; }
Writes a string to a temporary file, squashing exceptions

@param contents The string to write
@param path The file path
@param encoding The encoding to encode in