List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:com.yahoo.ycsb.db.RedisClient.java
public static String compressWithLog(String st) { // System.out.println("compress"); // System.out.println(st.substring(0, 20)); long start_time = System.nanoTime(); String ret = compress(st);//from w ww . j av a 2 s .c om try { long end_time = System.nanoTime(); long time = end_time - start_time; BufferedWriter bw = new BufferedWriter(new FileWriter("compress_time.txt", true)); bw.write("" + time); bw.newLine(); bw.flush(); BufferedWriter bw2 = new BufferedWriter(new FileWriter("compress_rate.txt", true)); double r1 = ret.length(); double r2 = st.length(); double r = r1 / r2; bw2.write("" + r); bw2.newLine(); bw2.flush(); } catch (Exception e) { } // System.out.println("compressed"); // System.out.println(ret.substring(0, 20)); return ret; }
From source file:com.axelor.apps.tool.file.FileTool.java
/** * Mthode permettant d'crire plusieurs lignes dans un fichier * @param destinationFolder/* ww w . jav a2 s . c om*/ * Le chemin du fichier * @param fileName * Le nom du fichier * @param line * La liste de ligne crire * @throws IOException */ public static void writer(String destinationFolder, String fileName, List<String> multiLine) throws IOException { System.setProperty("line.separator", "\r\n"); BufferedWriter output = null; try { File file = create(destinationFolder, fileName); output = new BufferedWriter(new FileWriter(file)); int i = 0; for (String line : multiLine) { output.write(line); output.newLine(); i++; if (i % 50 == 0) { output.flush(); } } } catch (IOException ex) { LOG.error(ex.getMessage()); } finally { if (output != null) { output.close(); } } }
From source file:playground.johannes.socialnets.GraphStatistics.java
public static void writeHistogram(Histogram1D hist, String filename) { try {/*ww w. j a v a2 s .c o m*/ BufferedWriter writer = IOUtils.getBufferedWriter(filename); writer.write("x\ty"); writer.newLine(); for (int i = 0; i < 100; i++) { writer.write(String.valueOf(hist.xAxis().binCentre(i))); writer.write("\t"); writer.write(String.valueOf(hist.binHeight(i))); writer.newLine(); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:playground.johannes.socialnets.GraphStatistics.java
public static void writeHistogramNormalized(Histogram1D hist, String filename) { try {/* w ww .j av a 2s . c o m*/ int maxBin = hist.minMaxBins()[1]; double maxY = hist.binHeight(maxBin); BufferedWriter writer = IOUtils.getBufferedWriter(filename); writer.write("x\ty"); writer.newLine(); for (int i = 0; i < 100; i++) { writer.write(String.valueOf(hist.xAxis().binCentre(i))); writer.write("\t"); writer.write(String.valueOf(hist.binHeight(i) / maxY)); writer.newLine(); } writer.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.hp.test.framework.Reporting.removerunlinks.java
public static void removelinksforpreRuns(String FilePath, String FileName, int lastrun) throws FileNotFoundException, IOException { log.info("Removing hyper link for the last run"); ArrayList<String> Links_To_Remove = new ArrayList<String>(); for (int i = 1; i < lastrun; i++) { Links_To_Remove.add("href=\"Run_" + i + "\\CurrentRun.html\""); }/*from ww w. j a v a 2s . c o m*/ File source = new File(FilePath + FileName); File temp_file = new File(FilePath + "temp.html"); BufferedReader in = new BufferedReader(new FileReader(source)); BufferedWriter out = new BufferedWriter(new FileWriter(temp_file)); String str = ""; while ((str = in.readLine()) != null) { String temp_ar[] = str.split(" "); for (int i = 0; i < temp_ar.length; i++) { String temp = temp_ar[i].trim(); if (!temp.equals("")) { if (Links_To_Remove.contains(temp)) { out.write(" "); out.newLine(); } else { out.write(temp); out.newLine(); } } } } out.close(); in.close(); out = null; in = null; source.delete(); temp_file.renameTo(source); }
From source file:atg.tools.dynunit.util.ComponentUtil.java
private static void writeComponentPropertiesToFile(final File output, final String canonicalClassName, final Properties properties) throws IOException { logger.entry(output, canonicalClassName, properties); BufferedWriter out = null; try {//from ww w . j ava 2s . c o m out = new BufferedWriter(new FileWriter(output)); if (StringUtils.isNotEmpty(canonicalClassName)) { out.write("$class="); out.write(canonicalClassName); out.newLine(); } properties.store(out, canonicalClassName); } finally { if (out != null) { out.close(); } logger.exit(); } }
From source file:gamlss.utilities.MatrixFunctions.java
/** * Write value to CSV file./*w w w .j a v a 2 s .co m*/ * @param cmd - path to the file * @param d - value */ public static void doubleWriteCSV(final String cmd, final double d, final boolean append) { try { // Create file FileWriter fstream = new FileWriter(cmd, append); BufferedWriter out = new BufferedWriter(fstream); out.write(Double.toString(d)); out.newLine(); out.close(); } catch (Exception e) { //Catch exception if any System.err.println("Error: " + e.getMessage()); } }
From source file:nu.mine.kino.projects.utils.WriteUtils.java
public static void writeAC(Project project, List<ACBean> returnList, File file) throws ProjectException { BufferedWriter writer = null; try {/* w w w . j av a2s.c om*/ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "MS932")); writer.write(getACHeader(project)); writer.newLine(); for (ACBean acBean : returnList) { TaskInformation taskInfo = ProjectUtils.getTaskInformation(project, acBean.getTaskId()); StringBuffer buf = new StringBuffer(); buf.append(taskInfo.getTask().getTaskSharp()); buf.append("\t"); buf.append(acBean.getTaskId()); buf.append("\t"); buf.append(taskInfo.getTask().getTaskName()); buf.append("\t"); buf.append(taskInfo.getTask().getPersonInCharge()); buf.append("\t"); if (!Double.isNaN(acBean.getActualCost())) { buf.append(acBean.getActualCost()); } String message = new String(buf); // System.out.println(message); writer.write(message, 0, message.length()); writer.newLine(); } } catch (FileNotFoundException e) { throw new ProjectException(e); } catch (IOException e) { throw new ProjectException(e); } finally { try { if (writer != null) { writer.flush(); writer.close(); } } catch (Exception e) { throw new ProjectException(e); } } }
From source file:nu.mine.kino.projects.utils.WriteUtils.java
public static void writeEV(Project project, List<EVBean> returnList, File file) throws ProjectException { BufferedWriter writer = null; try {//from www .jav a 2 s . c om writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "MS932")); writer.write(getEVHeader(project)); writer.newLine(); for (EVBean evBean : returnList) { TaskInformation taskInfo = ProjectUtils.getTaskInformation(project, evBean.getTaskId()); StringBuffer buf = new StringBuffer(); buf.append(taskInfo.getTask().getTaskSharp()); buf.append("\t"); buf.append(evBean.getTaskId()); buf.append("\t"); buf.append(taskInfo.getTask().getTaskName()); buf.append("\t"); buf.append(taskInfo.getTask().getPersonInCharge()); buf.append("\t"); if (!Double.isNaN(evBean.getEarnedValue())) { buf.append(evBean.getEarnedValue()); } buf.append("\t"); if (!Double.isNaN(evBean.getProgressRate())) { buf.append(evBean.getProgressRate()); } String message = new String(buf); // System.out.println(message); writer.write(message, 0, message.length()); writer.newLine(); } } catch (FileNotFoundException e) { throw new ProjectException(e); } catch (IOException e) { throw new ProjectException(e); } finally { try { if (writer != null) { writer.flush(); writer.close(); } } catch (Exception e) { throw new ProjectException(e); } } }
From source file:Main.java
public static void writeLifeLogCountInFile(int walking, int running, int vehicle, int bicycle, String filename) throws IOException { Date date = new Date(); BufferedWriter writer = null; File dir = new File(Environment.getExternalStorageDirectory() + "/LifeLog"); Log.d("Directory PATH", dir.getAbsolutePath()); boolean flag = dir.mkdir(); Log.d("Directory created?", "" + flag); File file = new File(dir.getAbsolutePath(), filename); if (file.exists() == false) { file.createNewFile();/*from w w w. j ava2 s. c om*/ writer = new BufferedWriter(new FileWriter(file, true)); writer.write("Date,Walking,Running,Bicycle,Vehicle"); writer.newLine(); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); } else { writer = new BufferedWriter(new FileWriter(file, true)); writer.write(date.toString() + "," + walking + "," + running + "," + bicycle + "," + vehicle); writer.newLine(); Log.d("Appended", "True"); } writer.flush(); writer.close(); }