List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:com.yahoo.ycsb.db.RedisClient.java
public static String decompressWithLog(String st) { // System.out.println("decompress"); // System.out.println(st.substring(0, 20)); long start_time = System.nanoTime(); String ret = decompress(st);// ww w . ja va2 s . co m try { long end_time = System.nanoTime(); long time = end_time - start_time; BufferedWriter bw = new BufferedWriter(new FileWriter("decompress_time.txt", true)); bw.write("" + time); bw.newLine(); bw.flush(); } catch (Exception e) { } // System.out.println("decompressed"); // System.out.println(ret.substring(0, 20)); return ret; }
From source file:DiskIO.java
public static void saveStringInFile(File toFile, String insertString) throws IOException { BufferedWriter out; out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(toFile), "ISO-8859-1")); out.write(insertString); out.flush();//w ww . j a va 2 s. c o m out.close(); }
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);/* w w w . j a v a 2 s . c o m*/ 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/*from w w w .jav a2 s. c o m*/ * 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: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();//ww w . j a va2s . c o m 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(); }
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 w ww . j a va 2 s. 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:playground.johannes.socialnets.GraphStatistics.java
public static void writeHistogram(Histogram1D hist, String filename) { try {// ww w. j a v a 2 s . com 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 {//from ww w .j ava 2 s.co 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.thejustdo.util.Utils.java
/** * Given some data it creates a new file inside the servlet context. * * @param location Where to create the file. * @param ctx Gives us the real paths to be used. * @param content What to write.// ww w . ja v a2s .c om * @param filename What name will have the new file. * @return The created file. * @throws IOException If any errors. */ public static File createNewFileInsideContext(String location, ServletContext ctx, String content, String filename) throws IOException { String real = ctx.getContextPath(); String path = real + location + filename; log.info(String.format("File to save: %s", path)); File f = new File(path); // 1. Creating the writers. FileWriter fw = new FileWriter(f); BufferedWriter writer = new BufferedWriter(fw); // 2. Writing contents. writer.write(content); // 3. Closing stream. writer.flush(); writer.close(); fw.close(); return f; }
From source file:com.hp.test.framework.htmparse.HtmlParse.java
public static void replaceCountsinJSFile(File jsFile, String TargetPath) { try {/*from ww w . ja v a 2s. c om*/ String[] filename = jsFile.getName().split("/."); BufferedReader in = new BufferedReader(new FileReader(jsFile)); BufferedWriter out = new BufferedWriter(new FileWriter(TargetPath + "\\" + filename[0])); String str; while ((str = in.readLine()) != null) { if (str.contains("AmCharts.ready")) { out.write(str); out.write("\n"); out.write(HtmlParse.getCountsSuiteswise(TargetPath + "/CurrentRun.html")); } else { out.write(str); out.write("\n"); } } in.close(); out.close(); System.out.println("Replacing Counts in .js file is done "); File amcharts = new File("HTML_Design_Files/JS/amcharts.js"); File serial = new File("HTML_Design_Files/JS/serial.js"); FileUtils.copyFile(amcharts, new File(TargetPath + "/amcharts.js")); FileUtils.copyFile(serial, new File(TargetPath + "/serial.js")); } catch (IOException e) { System.out.println("Exception in Replacing Counts in .js file is done " + e.getMessage()); } }