List of usage examples for java.io FileWriter close
public void close() 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(); }/*w w w . jav a 2s . c om*/ FileWriter writer = new FileWriter(licenseFile); writer.write(licenseText); writer.flush(); writer.close(); return true; } else { return false; } }
From source file:com.amazonaws.mturk.cmd.MakeTemplate.java
private static void generateScript(String scriptTemplateDir, String target, String targetDirPath, String command, CreateScriptUtil.ScriptType type) throws Exception { String scriptName = targetDirPath + File.separator + command + type.getExtension(); System.out.println("Generating script: " + scriptName); Map<String, String> input = new HashMap<String, String>(1); input.put("${target}", target); String templateFileName = scriptTemplateDir + File.separator + command + "." + type + ".template"; String source = CreateScriptUtil.generateScriptSource(type, input, templateFileName.toString()); FileWriter out = new FileWriter(scriptName); out.write(source);/* w ww .jav a2 s . c o m*/ out.close(); }
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 ww w .j a v 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:me.ardacraft.blocksapi.helper.LangHelper.java
public static void writeLangFile() { File out = FileHelper.externalConfigFile("assets/acblocks/lang", "en_US.lang"); try {/*w w w .j a v a2 s . c o m*/ FileWriter writer = new FileWriter(out); Collections.sort(entries); for (String s : entries) { writer.write(s); writer.append("\n"); } writer.close(); } catch (IOException e) { e.printStackTrace(); } entries.clear(); }
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 ava2 s .co 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:io.cloudslang.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java
public static void safeClose(FileWriter fis) { if (fis != null) { try {/*from w ww . j av a 2 s.c o m*/ fis.close(); } catch (IOException e) { System.out.println(e); } } }
From source file:ai.susi.json.JsonFile.java
/** * write a json file in transaction style: first write a temporary file, * then rename the original file to another temporary file, then rename the * just written file to the target file name, then delete all other temporary files. * @param file/*from ww w . j av a 2 s. c o m*/ * @param json * @throws IOException */ public static void writeJson(File file, JSONObject json) throws IOException { if (file == null) throw new IOException("file must not be null"); if (json == null) throw new IOException("json must not be null"); if (!file.exists()) file.createNewFile(); File tmpFile0 = new File(file.getParentFile(), file.getName() + "." + System.currentTimeMillis()); File tmpFile1 = new File(tmpFile0.getParentFile(), tmpFile0.getName() + "1"); FileWriter writer = new FileWriter(tmpFile0); writer.write(json.toString(2)); writer.close(); file.renameTo(tmpFile1); tmpFile0.renameTo(file); tmpFile1.delete(); }
From source file:com.grillecube.common.utils.JSONHelper.java
public static void writeJSONObjectToFile(File file, JSONObject json) { try {/*from w ww. j a 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:Main.java
public static boolean writeString(String filePath, String content) { File file = new File(filePath); if (!file.getParentFile().exists()) file.getParentFile().mkdirs();/*from w w w. j a v a 2s . c o m*/ FileWriter writer = null; try { writer = new FileWriter(file); writer.write(content); } catch (IOException e) { } finally { try { if (writer != null) { writer.close(); return true; } } catch (IOException e) { } } return false; }
From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Archivo.java
public static void vaciarArchivo(File archivo) { try {/*from w w w .j a va 2 s. co m*/ FileWriter fw = new FileWriter(archivo); fw.flush(); fw.close(); } catch (IOException e) { System.err.println(e); } }