List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:apps.LuceneIndexer.java
/** * Add one line to the TREC QREL file. // www . ja v a 2 s . c o m * * @param qrelFile * @param topicId * @param docId * @param relGrade */ public static void saveQrelOneEntry(BufferedWriter qrelFile, String topicId, String docId, int relGrade) throws IOException { qrelFile.write(String.format("%s 0 %s %d%s", topicId, docId, relGrade, NL)); }
From source file:com.alibaba.wasp.ZNodeClearer.java
/** * Logs the errors without failing on exception. *///from ww w. j a va2 s. c o m public static void writeMyEphemeralNodeOnDisk(String fileContent) { String fileName = ZNodeClearer.getMyEphemeralNodeFileName(); if (fileName == null) { LOG.warn("No filename given to save the znode used, it won't be saved " + "(Environment variable WASP_ZNODE_FILE is not set)."); return; } FileWriter fstream; try { fstream = new FileWriter(fileName); } catch (IOException e) { LOG.warn("Can't write znode file " + fileName, e); return; } BufferedWriter out = new BufferedWriter(fstream); try { try { out.write(fileContent + "\n"); } finally { try { out.close(); } finally { fstream.close(); } } } catch (IOException e) { LOG.warn("Can't write znode file " + fileName, e); } }
From source file:com.opensymphony.util.FileUtils.java
public final static void writeAndBackup(File file, String content) { try {/*www. j a v a2 s .c o m*/ DateFormat backupDF = new SimpleDateFormat("ddMMyy_hhmmss"); File backupDirectory = checkBackupDirectory(file); File original = new File(file.getAbsolutePath()); File backup = new File(backupDirectory, original.getName() + "." + backupDF.format(new Date())); if (log.isDebugEnabled()) { log.debug("Backup file is " + backup); } original.renameTo(backup); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (FileNotFoundException e) { log.warn("File not found", e); } catch (IOException e) { log.error(e); } }
From source file:com.book.jtm.chap03.HttpClientDemo.java
private static void writeParams(OutputStream output, List<NameValuePair> paramsList) throws IOException { StringBuilder paramStr = new StringBuilder(); for (NameValuePair pair : paramsList) { if (!TextUtils.isEmpty(paramStr)) { paramStr.append("&"); }//w w w . j a va 2 s .c om paramStr.append(URLEncoder.encode(pair.getName(), "UTF-8")); paramStr.append("="); paramStr.append(URLEncoder.encode(pair.getValue(), "UTF-8")); } BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); // ?? writer.write(paramStr.toString()); writer.flush(); writer.close(); }
From source file:com.github.jmabuin.blaspark.io.IO.java
public static void writeVectorToFileInHDFS(String file, DenseVector vector, Configuration conf) { try {//from ww w . ja v a2 s . c o m FileSystem fs = FileSystem.get(conf); Path pt = new Path(file); //FileSystem fileSystem = FileSystem.get(context.getConfiguration()); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fs.create(pt, true))); bw.write("%%MatrixMarket matrix array real general"); bw.newLine(); bw.write(vector.size() + " 1"); bw.newLine(); for (int i = 0; i < vector.size(); i++) { bw.write(String.valueOf(vector.apply(i))); bw.newLine(); } bw.close(); //fs.close(); } catch (IOException e) { LOG.error("Error in " + IO.class.getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:de.dakror.scpuller.SCPuller.java
public static void saveDownloadedSongs() { File f = new File(System.getProperty("user.home") + "/.dakror/SCPuller/downloaded.txt"); try {//from w w w.j av a 2s .c o m f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); for (int i : downloadedSongs) bw.write(i + "\r\n"); bw.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.hp.test.framework.htmparse.UpdateTestCaseDesciption.java
public static void replaceDetailsTable(String path) throws IOException { File source = new File(path); Document report = null;/*from www .jav a 2 s . c o m*/ try { report = Jsoup.parse(source, "UTF-8"); } catch (IOException e) { System.out.println("Unable to open [" + source.getAbsolutePath() + "] for parsing!"); } Elements dom = report.children(); Elements tds = report.select("table[id=tableStyle] td"); // select the tds from your table String temp_key = ""; for (Element td : tds) { // loop through them String[] temp_ar = td.toString().split("\""); String Key = temp_ar[1]; String Status = ""; if (td.toString().contains("pass.png")) { Status = "pass"; } if (td.toString().contains("fail.png")) { Status = "fail"; } if (td.toString().contains("skip.png")) { Status = "skip"; } if (TestCaseDesMap.containsKey(temp_key) && Status.length() > 1) { TestcaseStatusMap.put(temp_key, Status); temp_key = ""; } if (td.text().contains("Test Method")) { // found the one you want String TestcaseDes; if (!TestCaseDesMap.containsKey(Key)) { TestcaseDes = " --------- "; TestCaseDesMap.put(Key, TestcaseDes); temp_key = Key; } else { TestcaseDes = TestCaseDesMap.get(Key); temp_key = Key; // TestcaseStatusMap.put(Key, Status); } td.text(TestcaseDes); // Replace with your text } } Elements ths = report.select("table[id=tableStyle] th"); // select the tds from your table for (Element th : ths) { // loop through them if (th.text().contains("Method Type")) { // found the one you want th.text("TestCase Description"); } if (th.text().contains("Test Case Name")) { // found the one you want th.text("Testng Method"); } } if (!source.canWrite()) { System.out.println("Can't write this file!");//Just check if the file is writable or not } BufferedWriter bw = new BufferedWriter(new FileWriter(source)); bw.write(dom.toString()); //toString will give all the elements as a big string bw.close(); //Close to apply the changes // genarateFailureReport(new File("C:\\Users\\yanamalp\\Desktop\\Gen_jelly\\HTML_Design_Files\\CSS\\HtmlReport.html"), "c:\\"); }
From source file:eu.liveandgov.ar.utilities.OS_Utils.java
/** * Save a string into a file in SD *//*from ww w . j ava 2s . c o m*/ public static boolean write2File(String filename, String string) { try { FileWriter fstream = new FileWriter(filename); BufferedWriter out = new BufferedWriter(fstream); out.write(string); out.close(); fstream.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:apm.generate.Generate.java
/** * //from www . j a va 2 s. c om * @param content * @param filePath */ public static void writeFile(String content, String filePath) { try { if (FileUtils.createFile(filePath)) { FileWriter fileWriter = new FileWriter(filePath, true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(content); bufferedWriter.close(); fileWriter.close(); } else { //logger.info("??"); System.out.println("??"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.thinkit.operationsys.util.FileUtil.java
/** * ?//w ww.ja v a2 s .c om * * @param fileName * @param data */ public static void write(String fileName, String data) { BufferedWriter bw = null; try { // String name = getName(link) + "analyze.txt"; bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))); bw.write(data); bw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (null != bw) { try { bw.close(); } catch (IOException e) { e.printStackTrace(); } } } }