List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:ir.pooyahfp.matrixcli.ProgramTest.java
@Test public void testLoadCommandFile() throws Exception { String path = "test.txt"; BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path))); writer.write("matrix x 3 3"); writer.newLine(); writer.write("show x"); writer.flush();//from www . j av a 2 s. c o m writer.close(); program.loadCommandFile(path); }
From source file:mattmc.mankini.commands.CommandQuote.java
private void addQuote(String content, MessageEvent<PircBotX> event) { try {// ww w . j ava 2s . co m if (!file.exists()) { System.out.println(file.createNewFile()); } FileWriter fw; fw = new FileWriter(file, true); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.newLine(); bw.close(); MessageSending.sendNormalMessage("Quote Added!", event); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.smart.common.officeFile.CSVUtils.java
/** * * @param exportData ?/*from w w w. j a va2 s . c o m*/ * @param rowMapper ?? * @param outPutPath * @param filename ?? * @return */ public static File createCSVFile(List exportData, LinkedHashMap rowMapper, String outPutPath, String filename) { File csvFile = null; BufferedWriter csvFileOutputStream = null; try { csvFile = new File(outPutPath + filename + ".csv"); // csvFile.getParentFile().mkdir(); File parent = csvFile.getParentFile(); if (parent != null && !parent.exists()) { parent.mkdirs(); } csvFile.createNewFile(); // GB2312?"," csvFileOutputStream = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(csvFile), "GB2312"), 1024); // for (Iterator propertyIterator = rowMapper.entrySet().iterator(); propertyIterator.hasNext();) { java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); csvFileOutputStream.write("\"" + propertyEntry.getValue().toString() + "\""); if (propertyIterator.hasNext()) { csvFileOutputStream.write(","); } } csvFileOutputStream.newLine(); // for (Iterator iterator = exportData.iterator(); iterator.hasNext();) { LinkedHashMap row = (LinkedHashMap) iterator.next(); System.out.println(row); for (Iterator propertyIterator = row.entrySet().iterator(); propertyIterator.hasNext();) { java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); // System.out.println(BeanUtils.getProperty(row, propertyEntry.getKey().toString())); csvFileOutputStream.write("\"" + propertyEntry.getValue().toString() + "\""); if (propertyIterator.hasNext()) { csvFileOutputStream.write(","); } } // for (Iterator propertyIterator = row.entrySet().iterator(); propertyIterator.hasNext();) { // java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); // System.out.println(BeanUtils.getProperty(row, propertyEntry.getKey().toString())); // csvFileOutputStream.write("\"" // + BeanUtils.getProperty(row, propertyEntry.getKey().toString()) + "\""); // if (propertyIterator.hasNext()) { // csvFileOutputStream.write(","); // } // } if (iterator.hasNext()) { csvFileOutputStream.newLine(); } } csvFileOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { csvFileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return csvFile; }
From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNumActionsStatistics.java
public void writeSessionsOverTime(final String outputDir) throws IOException { FileWriter fw = new FileWriter(outputDir + "/" + this.getClass().getSimpleName() + "-sessionLengths.csv"); BufferedWriter writer = new BufferedWriter(fw); writer.write("length"); writer.newLine(); for (double l : this.computeLengthVector()) { writer.write(Double.toString(l)); writer.newLine();//from ww w . j a v a 2s .c o m } writer.close(); fw.close(); }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static void prettyOutputStrings(List<Object> objs, String fileName, String delimeter) throws Exception { StringBuffer buff = new StringBuffer(); if (isBlank(delimeter)) { delimeter = System.lineSeparator(); }/*from w ww . j a v a 2 s . com*/ for (Object obj : objs) { if (obj != null) { String str = obj.toString(); if (!isBlank(str)) { buff.append(str).append(delimeter); } } } if (buff.length() > 0) { buff.delete(buff.length() - delimeter.length(), buff.length()); } OutputStream out = null; BufferedWriter bw = null; try { if (!isBlank(fileName)) { out = new FileOutputStream(fileName); } else { out = System.out; } bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); bw.write(buff.toString()); if (!isBlank(fileName)) { // [Bug 1406542] always append a newline at the end of the file bw.newLine(); } bw.flush(); } finally { if (bw != null && out != null && !(out instanceof PrintStream)) { bw.close(); out.close(); } } }
From source file:net.sf.sessionAnalysis.SessionVisitorSessionLengthNanosStatistics.java
public void writeSessionsOverTime(final String outputDir) throws IOException { FileWriter fw = new FileWriter( outputDir + "/" + this.getClass().getSimpleName() + "-sessionLengthsNanoSeconds.csv"); BufferedWriter writer = new BufferedWriter(fw); writer.write("lengthNanos"); writer.newLine(); for (double l : this.computeLengthVector()) { writer.write(Double.toString(l)); writer.newLine();// www . j a v a 2s . c o m } writer.close(); fw.close(); }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
private static void writeSimilarityToTextFile(double[][] similarities) { try {// w w w .j av a 2s . c o m FileOutputStream fos = new FileOutputStream(outputFile); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < similarities.length; i++) { for (int j = 0; j < similarities[0].length; j++) { writer.write(String.format("%f,", similarities[i][j])); } writer.newLine(); } writer.close(); fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.depas.utils.FileUtils.java
public static void writeArrayToFile(String fileName, String[] contents, boolean utfEncoding) throws IOException { BufferedWriter out = null; try {/*www. j a v a 2s .co m*/ File outFile = new File(fileName); OutputStreamWriter osw; if (utfEncoding) { osw = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"); } else { osw = new OutputStreamWriter(new FileOutputStream(outFile)); } out = new BufferedWriter(osw); for (int i = 0; i < contents.length; i++) { out.write(contents[i]); out.newLine(); } out.close(); out = null; } finally { if (out != null) { out.close(); } } }
From source file:org.openmrs.module.atomfeed.AtomFeedUtil.java
/** * Does the work of writing the given object update to the feed file * //from w w w. ja va2 s . c o m * @param action what happened * @param object the object that was changed * @should initialize header file * @should change updated time in existing header file * @should prepend valid entry to entries file */ protected static synchronized void writeToFeed(String action, OpenmrsObject object) { // get handle on file for entries File atomfile = getFeedEntriesFile(); // write action/change to file String entry = getEntry(action, object); // prepend given entry string to the beginning of atom file BufferedWriter out = null; FileInputStream source = null; FileOutputStream destination = null; File temporaryAtomFile = null; try { // create hidden temporary atom file within atom feeds // directory to write new feed entry to if (!atomfile.exists()) { out = new BufferedWriter(new FileWriter(atomfile, Boolean.TRUE)); out.write(entry); out.newLine(); } else { temporaryAtomFile = new File(atomfile.getParent(), ".".concat(atomfile.getName())); out = new BufferedWriter(new FileWriter(temporaryAtomFile, Boolean.TRUE)); out.write(entry); out.newLine(); // copy existing atom feed entries from current atom feed file // to temporary file BufferedReader br = new BufferedReader(new FileReader(atomfile)); while ((entry = br.readLine()) != null) { out.write(entry); out.newLine(); } out.flush(); IOUtils.closeQuietly(out); // get rid of old feed entries file by swap it's content with new one source = new FileInputStream(temporaryAtomFile); destination = new FileOutputStream(atomfile); IOUtils.copy(source, destination); } } catch (IOException e) { log.error("Unable to write entry to the feed entries file, because of error:", e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(source); IOUtils.closeQuietly(destination); FileUtils.deleteQuietly(temporaryAtomFile); } // get handle on header file File atomheaderfile = getFeedHeaderFile(); // re-/creates the header and/or updates the "last updated" time to now // the entire file doesn't always need rewritten for every entry, // but its not that large, so we're not losing many cpu cycles // TODO: look into only changing the "updated" element to reduce cpu // usage -- ATOM-4 updateFeedFileHeader(atomheaderfile, atomfile.length()); }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void dumpLimits(EurostagDictionary dictionary, BufferedWriter writer, String branchId, CurrentLimits cl1, CurrentLimits cl2, float nominalV1, float nominalV2) throws IOException { writer.write(dictionary.getEsgId(branchId)); writer.write(";"); writer.write(Float.toString(cl1 != null ? cl1.getPermanentLimit() : Float.MAX_VALUE)); writer.write(";"); writer.write(Float.toString(cl2 != null ? cl2.getPermanentLimit() : Float.MAX_VALUE)); writer.write(";"); writer.write(Float.toString(nominalV1)); writer.write(";"); writer.write(Float.toString(nominalV2)); writer.write(";"); writer.write(branchId);/*from w w w . j a v a 2s.c o m*/ writer.newLine(); }