List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:it.moondroid.chatbot.alice.Sraix.java
public static void log(String pattern, String template) { System.out.println("Logging " + pattern); template = template.trim();/*from w w w . j ava 2 s. c o m*/ if (MagicBooleans.cache_sraix) try { if (!template.contains("<year>") && !template.contains("No facilities")) { template = template.replace("\n", "\\#Newline"); template = template.replace(",", MagicStrings.aimlif_split_char_name); template = template.replaceAll("<a(.*)</a>", ""); template = template.trim(); if (template.length() > 0) { FileWriter fstream = new FileWriter("c:/ab/bots/sraixcache/aimlif/sraixcache.aiml.csv", true); BufferedWriter fbw = new BufferedWriter(fstream); fbw.write("0," + pattern + ",*,*," + template + ",sraixcache.aiml"); fbw.newLine(); fbw.close(); } } } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:com.packtpub.mahout.cookbook.chapter01.App.java
private static void CreateCsvRatingsFile() throws FileNotFoundException, IOException { BufferedReader br = new BufferedReader(new FileReader(inputFile)); BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile)); String line = null;/* ww w. j a va 2 s . c o m*/ String line2write = null; String[] temp; int i = 0; while ((line = br.readLine()) != null && i < 1000) { i++; temp = line.split("::"); line2write = temp[0] + "," + temp[1]; bw.write(line2write); bw.newLine(); bw.flush(); } br.close(); bw.close(); }
From source file:com.termmed.statistics.runner.Runner.java
/** * Save info./* w w w.java 2s .c o m*/ * * @throws IOException Signals that an I/O exception has occurred. */ private static void saveInfo() throws IOException { Gson gson = new GsonBuilder().setPrettyPrinting().create(); BufferedWriter bw = FileHelper .getWriter(new File(I_Constants.PROCESS_INFO_FOLDER, "analyticsResults.json")); bw.append(gson.toJson(OutputInfoFactory.get()).toString()); bw.close(); }
From source file:fr.ece.epp.tools.Utils.java
public static void writeScript(String path, String version) { String system = System.getProperty("os.name"); try {//from w w w. j av a2 s.c o m if (system.startsWith("Windows")) { File writename = new File(path); writename.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("%~d0\n\r"); out.write("cd %~dp0\n\r"); out.write("mvn install -P base," + version); out.flush(); // out.close(); // ? } else if (system.startsWith("Linux") || system.startsWith("Mac")) { File writename = new File(path); writename.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(writename)); out.write("#!/bin/sh\n\n"); out.write("BASEDIR=$(dirname $0)\n"); out.write("cd $BASEDIR\n"); out.write("mvn install -P base," + version); out.flush(); // out.close(); // ? } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:de.uzk.hki.da.sb.restfulService.FileUtil.java
/** * Method appends a String to File/* w w w .ja v a2s . c o m*/ * @param fileName * @param contentString * @return */ public static String appendStringToResultFile(String fileName, String contentString) { FileWriter fw = null; try { inputFile = new File(Configuration.getResultDirPath() + fileName); fw = new FileWriter(inputFile, true); log.info(Configuration.getResultDirPath()); BufferedWriter bw = new BufferedWriter(fw); bw.append(contentString); bw.flush(); bw.close(); } catch (IOException ioExc) { log.error(ioExc); } finally { if (fw != null) { try { fw.close(); } catch (IOException ioExc) { log.error(ioExc); } } } log.info("File-Size, Ergebnis: " + inputFile.length()); return inputFile.getName(); }
From source file:com.vmware.identity.interop.PlatformUtils.java
private static boolean renameFileOnWindows(File oldFile, File newFile) { String sCurrentLine = ""; try {/*from ww w . jav a2 s . c o m*/ BufferedReader bufReader = new BufferedReader(new FileReader(oldFile.getAbsoluteFile())); BufferedWriter bufWriter = new BufferedWriter(new FileWriter(newFile.getAbsoluteFile())); while ((sCurrentLine = bufReader.readLine()) != null) { bufWriter.write(sCurrentLine); bufWriter.newLine(); } bufReader.close(); bufWriter.close(); oldFile.delete(); return true; } catch (Exception e) { return false; } }
From source file:com.android.dumprendertree2.FsUtils.java
public static void saveTestListToStorage(File file, int start, List<String> testList) { try {/*ww w . j a v a2 s .com*/ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); for (String line : testList.subList(start, testList.size())) { writer.write(line + '\n'); } writer.flush(); writer.close(); } catch (IOException e) { Log.e(LOG_TAG, "failed to write test list", e); } }
From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java
public static void createEmptyUsersFile(String fileName) { File xmlFile = new File(fileName); BufferedWriter writer; try {/*w w w . j av a2 s. c o m*/ writer = new BufferedWriter(new FileWriter(xmlFile)); } catch (IOException e) { e.printStackTrace(); return; } try { IOUtils.writeLines(Arrays.asList(emptyFileLines), System.getProperty("line.separator"), writer); writer.close(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.cemso.util.CheckDeviceStateExcuter.java
public static void checkWait() { if (log.isInfoEnabled()) { log.info("auto refresh is waiting..."); try {/*from ww w . ja v a 2 s. co m*/ File f = new File("C:/DLLfunctionsTest.txt"); FileWriter fw = new FileWriter(f, true); BufferedWriter bw = new BufferedWriter(fw); bw.newLine(); bw.append(new java.util.Date().toString() + ": auto refresh is waiting..."); bw.newLine(); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } checkerHandle1.cancel(true); }
From source file:com.egt.core.util.VelocityEngineer.java
public static void write(VelocityContext context, String tempname, String filename) throws Exception { Bitacora.trace(VelocityEngineer.class, "write", context, tempname, filename); StringWriter sw = write(context, tempname); if (sw != null) { FileWriter fileWriter = null; BufferedWriter bufferedWriter = null; try {/* w ww . java 2 s. c om*/ fileWriter = new FileWriter(filename); bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(sw.toString()); } catch (IOException ex) { throw ex; } finally { if (bufferedWriter != null) { try { bufferedWriter.close(); } catch (IOException ex) { Bitacora.logFatal(ex); } } if (fileWriter != null) { try { fileWriter.close(); } catch (IOException ex) { Bitacora.logFatal(ex); } } } } }