List of usage examples for java.io FileWriter flush
public void flush() throws IOException
From source file:com.atlassian.clover.eclipse.core.licensing.LicenseUtils.java
public static boolean writeLicenseTo(File licenseFile) throws IOException { String licenseText = CloverPlugin.getInstance().getInstallationSettings().getLicenseText(); if (licenseFile != null) { if (!licenseFile.exists()) { licenseFile.createNewFile(); }//from www .j a v a2s .c o m FileWriter writer = new FileWriter(licenseFile); writer.write(licenseText); writer.flush(); writer.close(); return true; } else { return false; } }
From source file:gov.nih.nci.firebird.commons.test.TestFileUtils.java
/** * Creates a temporary file which will be deleted upon JVM exit. * * @return temporary file/*from w ww .j av a 2 s . c o m*/ * @throws IOException if there is a problem creating a temporary file */ public static File createTemporaryFile() throws IOException { File file = File.createTempFile("temp_", ".tmp"); file.createNewFile(); FileWriter fileWriter = new FileWriter(file); fileWriter.append(SimpleDateFormat.getDateTimeInstance().format(new Date())); fileWriter.flush(); fileWriter.close(); FileUtils.forceDeleteOnExit(file); return file; }
From source file:com.dalthed.tucan.TucanMobile.java
/** * Writes a note on the SD. Only Used for Development purposes * @param sFileName Filname// w ww . j av a 2 s . c o m * @param sBody content * @param mContext App Context */ public static void generateNoteOnSD(String sFileName, String sBody, Context mContext) { try { File root = new File(Environment.getExternalStorageDirectory(), "Notes"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, sFileName); FileWriter writer = new FileWriter(gpxfile); writer.append(sBody); writer.flush(); writer.close(); //Toast.makeText(mContext, "Saved", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); String importError = e.getMessage(); Log.e("TuCanMobile", importError); } }
From source file:com.grillecube.common.utils.JSONHelper.java
public static void writeJSONObjectToFile(File file, JSONObject json) { try {/*from ww w. ja v a2s . c o m*/ file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write(json.toString()); writer.flush(); writer.close(); } catch (Exception e) { return; } }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditingTestsUtils.java
static void writeToFile(File file, String fileContent) { try {/*from ww w . j ava 2 s.co m*/ FileWriter writer = new FileWriter(file); writer.write(fileContent); writer.flush(); writer.close(); } catch (Exception exception) { throw new AuditingException(exception, "Error writing content to file '%s'.", file.getAbsolutePath()); } }
From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Archivo.java
public static void vaciarArchivo(File archivo) { try {/*from w w w.j a v a 2s .c om*/ FileWriter fw = new FileWriter(archivo); fw.flush(); fw.close(); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void writeToFile(Collection<?> collection, File file) throws IOException { if (collection != null && file != null) { file.getParentFile().mkdirs();/*from ww w . j a v a 2s.c o m*/ File tempFile = new File(file.getAbsolutePath() + ".tmp"); FileWriter fw = new FileWriter(tempFile); for (Object obj : collection) { fw.write(new StringBuilder(obj.toString()).append("\r\n").toString()); } fw.flush(); fw.close(); file.delete(); tempFile.renameTo(file); } }
From source file:Main.java
public static void writeToFile(Iterator<?> iter, File file) throws IOException { if (iter != null && file != null) { file.getParentFile().mkdirs();//from ww w. j a va 2s .c om File tempFile = new File(file.getAbsolutePath() + ".tmp"); FileWriter fw = new FileWriter(tempFile); for (; iter.hasNext();) { fw.write(new StringBuilder(iter.next().toString()).append("\r\n").toString()); } fw.flush(); fw.close(); file.delete(); tempFile.renameTo(file); } }
From source file:com.eucalyptus.gen2ools.TemplateGenerator.java
private static void writeTemplate(VelocityContext context, String templateName, File outFile) { if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); }//from w ww .ja v a 2s. co m Template template = null; try { template = Velocity.getTemplate(templateName); FileWriter out = new FileWriter(outFile); template.merge(context, out); out.flush(); out.close(); } catch (ResourceNotFoundException ex) { // couldn't find the template LOG.error(ex, ex); } catch (ParseErrorException ex) { // syntax error: problem parsing the template LOG.error(ex, ex); } catch (MethodInvocationException ex) { // something invoked in the template // threw an exception LOG.error(ex, ex); } catch (IOException ex) { LOG.error(ex, ex); } }
From source file:com.grillecube.engine.renderer.model.json.JSONHelper.java
public static void writeJSONObjectToFile(File file, JSONObject json) { try {//www .ja v a 2 s.c o m FileWriter writer = new FileWriter(file); writer.write(json.toString()); writer.flush(); writer.close(); } catch (Exception e) { return; } }