List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:com.roquahacks.semafor4j.FrameNetService.java
public void writeOptionsToConfig() { try {/*from www. j a v a2s . c om*/ this.configFile = FileUtils.readLines(new File(FrameNetOptions.ABS_PATH_FILE_CONFIG)); BufferedWriter bw = new BufferedWriter(new FileWriter(new File(FrameNetOptions.ABS_PATH_FILE_CONFIG))); for (String s : configFile) { if (s.startsWith(SEMAFOR_HOME)) { s = SEMAFOR_HOME + FrameNetOptions.ABS_PATH_SEMAFOR; } else if (s.startsWith(MST_MODE)) { if (this.fnOpt.isServerModeOn()) { s = MST_MODE + "server"; } else { s = MST_MODE + "noserver"; } } else if (s.startsWith(JAVA_HOME)) { s = JAVA_HOME + this.fnOpt.getJavaHomePath(); } else if (s.startsWith(GOLD_TARGET_FILE)) { s = GOLD_TARGET_FILE + this.fnOpt.getGoldTargetsPath(); } else if (s.startsWith(AUTO_TARGET_ID_MODE)) { if (this.fnOpt.isAutoTargetIDStrictModeOn()) { s = AUTO_TARGET_ID_MODE + "strict"; } else { s = AUTO_TARGET_ID_MODE + "relaxed"; } } else if (s.startsWith(USE_GRAPH_FILES)) { if (this.fnOpt.isGraphFilesOn()) { s = USE_GRAPH_FILES + "yes"; } else { s = USE_GRAPH_FILES + "no"; } } else if (s.startsWith(DECODING_TYPE)) { s = DECODING_TYPE + this.fnOpt.getDecodingType(); } bw.write(s); bw.newLine(); } bw.flush(); bw.close(); this.configFile.clear(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:eu.liveandgov.ar.utilities.OS_Utils.java
/** * Save a string into a file in SD *///from ww w . j av a 2 s. com 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:de.knurt.heinzelmann.util.Outputops.java
/** * writes the content (strings!) of a vector into the given output and * returns true, if everything worded fine. * //from w w w . jav a 2 s. c om * @param v * - vector with strings(!) to write into the file * @param f * - the file to write in * @return true, if everything works fine */ public boolean writeCharsToFile(Vector<?> v, File f) { boolean done = false; String[] out = vo.vectorToStringarray(v); if (f.exists()) { FileWriter fwStream = null; PrintWriter pwStream = null; BufferedWriter bw = null; try { fwStream = new FileWriter(f); pwStream = new PrintWriter(fwStream); bw = new BufferedWriter(pwStream); for (int i = 0; i < out.length; i++) { IOUtils.write(out[i] + "\n", bw); } done = true; } catch (IOException io) { System.out.println(io); } finally { IOUtils.closeQuietly(fwStream); IOUtils.closeQuietly(pwStream); IOUtils.closeQuietly(bw); } } else { System.out.println("output doesn't existes"); done = false; } return done; }
From source file:edu.illinois.cs.cogcomp.wikifier.wiki.importing.WikipediaRedirectExtractor.java
public String run(File inputFile, File outputFile) throws Exception { int invalidCount = 0; long t0 = System.currentTimeMillis(); InputStream fis = new FileInputStream(inputFile); if (inputFile.getName().endsWith(".bz2")) fis = new BZip2InputStream(fis, false); BufferedReader dumpReader = new BufferedReader(new InputStreamReader(fis, "utf-8")); BufferedWriter redirectWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8")); String titleIdFile = outputFile + "-title-id.txt"; BufferedWriter titleIdWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(titleIdFile), "utf-8")); int count = 0; String title = null;/* ww w. j a v a2 s .c o m*/ String line = null; while ((line = dumpReader.readLine()) != null) { if (line.startsWith(titlePattern)) { title = cleanupTitle(line); continue; } if (line.startsWith(redirectPattern)) { String[] splits = StringUtils.substringsBetween(line, "<redirect title=\"", "\" />"); if (splits == null || splits.length != 1) { invalidCount++; continue; } String redirectedTitle = splits[0]; redirectedTitle = cleanupTitle(redirectedTitle); if (isValidAlias(title, redirectedTitle)) { redirectWriter.write(title + "\t" + redirectedTitle); redirectWriter.newLine(); count++; } else { invalidCount++; System.out.println("Discarded redirect from " + title + " to " + redirectedTitle); } if (count % 100000 == 0) System.out.println("Processed " + (count + invalidCount) + " titles "); } if (SAVE_COMPLETE_TITLE_LIST && line.startsWith(idPattern)) { String[] splits = StringUtils.substringsBetween(line, "<id>", "</id>"); if (splits == null || splits.length != 1) { invalidCount++; continue; } titleIdWriter.write(splits[0] + '\t' + title); titleIdWriter.newLine(); } } dumpReader.close(); fis.close(); redirectWriter.close(); titleIdWriter.close(); System.out.println("---- Wikipedia redirect extraction done ----"); long t1 = System.currentTimeMillis(); // IOUtil.save( map ); System.out.println("Discarded " + invalidCount + " redirects to wikipedia meta articles."); System.out.println("Extracted " + count + " redirects."); System.out.println("Saved output: " + outputFile.getAbsolutePath()); System.out.println("Done in " + ((t1 - t0) / 1000) + " sec."); return titleIdFile; }
From source file:localization.split.java
public static boolean checkLPU(String filepath, String passoloPath) { File logfile = new File(filepath.substring(0, filepath.lastIndexOf("\\") + 1) + "error.log"); try {//from ww w. j ava2 s . c om String cmd = "cmd.exe /c " + passoloPath + " /openproject:" + filepath; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd); InputStreamReader isr = new InputStreamReader(proc.getInputStream()); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { if (line.contains("Opening in read-only mode")) { if (!logfile.exists()) { logfile.createNewFile(); } String content = filepath + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2011." + "\n"; FileWriter fw = new FileWriter(logfile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); return false; } } int exitVal = proc.waitFor(); if (exitVal == 10) { if (!logfile.exists()) { logfile.createNewFile(); } String content = filepath + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2015." + "\n"; FileWriter fw = new FileWriter(logfile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); return false; } } catch (Exception e) { try { String content = e.getMessage(); FileWriter fw = new FileWriter(logfile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); } catch (Exception e1) { } return false; } return true; }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetPlatformListener.java
@Override public void handleEvent(Event event) { Vector<String> values = this.ui.getValues(); Vector<String> samples = this.ui.getSamples(); File file = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".subject_mapping.tmp"); File mappingFile = ((SnpData) this.dataType).getMappingFile(); if (mappingFile == null) { this.ui.displayMessage("Error: no subject to sample mapping file"); }//from w ww. j a v a2s .c o m try { FileWriter fw = new FileWriter(file); BufferedWriter out = new BufferedWriter(fw); try { BufferedReader br = new BufferedReader(new FileReader(mappingFile)); String line; while ((line = br.readLine()) != null) { String[] fields = line.split("\t", -1); String sample = fields[3]; String platform; if (samples.contains(sample)) { platform = values.get(samples.indexOf(sample)); } else { br.close(); return; } out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n"); } br.close(); } catch (Exception e) { this.ui.displayMessage("Error: " + e.getLocalizedMessage()); out.close(); e.printStackTrace(); } out.close(); try { File fileDest; if (mappingFile != null) { String fileName = mappingFile.getName(); mappingFile.delete(); fileDest = new File(this.dataType.getPath() + File.separator + fileName); } else { fileDest = new File(this.dataType.getPath() + File.separator + this.dataType.getStudy().toString() + ".subject_mapping"); } FileUtils.moveFile(file, fileDest); ((SnpData) this.dataType).setMappingFile(fileDest); } catch (IOException ioe) { this.ui.displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.ui.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } this.ui.displayMessage("Subject to sample mapping file updated"); WorkPart.updateSteps(); WorkPart.updateFiles(); }
From source file:m3umaker.exFiles.java
public void genFile(String Path, String M3UfileName, List Files) { try {//from www .ja v a 2 s . co m BufferedWriter out = new BufferedWriter(new FileWriter(Path + "\\" + M3UfileName + ".m3u", true)); for (int i = 0; i < Files.size(); i++) { out.write(Files.get(i).toString()); out.newLine(); } out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.alibaba.wasp.ZNodeClearer.java
/** * Logs the errors without failing on exception. *//*from w w w . j ava 2 s .c om*/ 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:sample.server.NativeGemFireServer.java
private static void writeStringTo(File file, String fileContents) { PrintWriter fileWriter = null; try {//from w ww. jav a2 s .co m fileWriter = new PrintWriter(new BufferedWriter(new FileWriter(file, true)), true); fileWriter.println(fileContents); fileWriter.flush(); } catch (IOException e) { throw new RuntimeException(String.format("Failed to write [%s] to file [%s]", fileContents, file), e); } finally { if (fileWriter != null) { fileWriter.close(); } } }
From source file:com.almarsoft.GroundhogReader.lib.FSUtils.java
public static void writeStringToDiskFile(String data, String fullPath, String fileName) throws IOException { File outDir = new File(fullPath); if (!outDir.exists()) outDir.mkdirs();/*from w ww. j a v a 2 s . com*/ BufferedWriter out = null; try { FileWriter writer = new FileWriter(fullPath + fileName); out = new BufferedWriter(writer); out.write(data); out.flush(); } finally { if (out != null) out.close(); } }