List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:actors.ConfigUtil.java
/** * Generate the config file in the 'wherehows.app_folder' folder * The file name is {whEtlExecId}.config * * @param whEtlExecId//from ww w . j a v a 2s . c om * @param props * @return void */ static void generateProperties(long whEtlExecId, Properties props, String outDir) throws IOException { File dir = new File(outDir); if (!dir.exists()) { dir.mkdirs(); } File configFile = new File(dir, whEtlExecId + ".properties"); FileWriter writer = new FileWriter(configFile); props.store(writer, "exec id : " + whEtlExecId + " job configurations"); writer.close(); }
From source file:id.co.nlp.MachineTranslation.Utils.Util.java
public static void write(String Url, String Teks) { FileWriter writer; try {/*w ww . j a v a 2 s . co m*/ writer = new FileWriter(Url); writer.write(Teks); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void writeFile(String writr_str, boolean add) { try {//from w w w . ja v a 2 s. c o m FileWriter fout = new FileWriter(mFilePath, add); fout.write(writr_str); if (add) { fout.write("\r\n"); } else { } fout.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:SageCollegeProject.guideBox.java
public static void WriteJsonToFile(String json, String fileName) { CheckMakeDir(fileName.substring(0, fileName.lastIndexOf("/"))); try {//from www. j a va 2 s .co m FileWriter writer = new FileWriter(fileName); writer.write(json); writer.close(); } catch (IOException ex) { System.out.println("Error writing SCPGuideBox json file to disk"); System.out.println(ex); } }
From source file:Main.java
public static boolean writeFile(String filePath, String content, boolean append) { FileWriter fileWriter = null; try {/*from ww w. ja va 2s.c o m*/ fileWriter = new FileWriter(filePath, append); fileWriter.write(content); fileWriter.close(); return true; } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
From source file:cfd.backupper.state.StartupConfig.java
public static void putSetting(String key, List l) { //l needs to be toString(), otherwise there are no doublequotes in JSON. List stringedList = (List) l.stream().map(elem -> elem.toString()).collect(Collectors.toList()); if (jo.containsKey(key)) { jo.replace(key, stringedList);// ww w. j a v a 2 s . c o m } else { jo.put(key, stringedList); } try { FileWriter fw = new FileWriter(confFile, false); fw.append(jo.toJSONString()); fw.flush(); fw.close(); } catch (IOException ex) { Logger.getLogger(StartupConfig.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties// w w w . java2 s . co m * @param checkFileExists * @param property * @param value * @throws java.io.IOException */ public static void setProperties(File properties, boolean checkFileExists, String property, String value) throws IOException { if (checkFileExists && !properties.exists()) { logger.error("Properties file [" + properties.getAbsolutePath() + "] does not exist."); throw new FileNotFoundException("Properties file does not found."); // IOHelper.delete(dbProperties); } Properties props = new Properties(); if (properties.exists()) { FileReader reader = new FileReader(properties); props.load(reader); reader.close(); } props.put(property, value); FileWriter writer = new FileWriter(properties); props.store(writer, null); writer.flush(); writer.close(); }
From source file:Main.java
public static int removeUnusedLines(String filename, SortedSet<Integer> linesSet) { try {// w ww . j av a2 s. c om BufferedReader br = new BufferedReader(new FileReader(filename)); //String buffer to store contents of the file StringBuffer sb = new StringBuffer(""); int lineNumber = 1; String line; Iterator iterator = linesSet.iterator(); int lineNumberToBeDeleted = (int) iterator.next(); int count = 0; while ((line = br.readLine()) != null) { if (lineNumber == lineNumberToBeDeleted) { if (iterator.hasNext()) { lineNumberToBeDeleted = (int) iterator.next(); count++; } } else { sb.append(line + "\n"); } lineNumber++; } FileWriter fw = new FileWriter(new File(filename)); //Write entire string buffer into the file fw.write(sb.toString()); fw.close(); System.err.println("deleted lines" + count); } catch (Exception e) { System.err.println("error:" + e.getMessage()); e.printStackTrace(); return -10; } return 10; }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties// w w w. j a va 2s . co m * @param append * @throws java.io.IOException */ public static void setProperties(File properties, Map<String, String> append) throws IOException { Properties props = new Properties(); if (properties.exists()) { FileReader reader = new FileReader(properties); props.load(reader); reader.close(); } else { FileUtils.forceMkdir(properties.getParentFile()); } if (properties.exists() || properties.createNewFile()) { props.putAll(append); FileWriter writer = new FileWriter(properties); props.store(writer, null); writer.flush(); writer.close(); } }
From source file:au.org.ala.layers.util.BatchProducer.java
private static void writeToFile(String filename, String string) throws IOException { FileWriter fw = new FileWriter(filename); fw.write(string);/*from w w w .j a va2 s. com*/ fw.close(); }