List of usage examples for java.io PrintWriter close
public void close()
From source file:Main.java
public static String exception2String(Exception e) { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); PrintWriter err = new PrintWriter(arrayOutputStream); e.printStackTrace(err);//from w w w. ja v a 2 s . com err.close(); try { arrayOutputStream.close(); } catch (IOException e1) { } return arrayOutputStream.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.boilerplate.standalone.HTMLBoilerplateRemoval.java
public static void processHtmlFile(File input, File outFile, boolean keepMinimalHtml) throws IOException { // read the html file String html = FileUtils.readFileToString(input, "utf-8"); // boilerplate removal String cleanText;/*from ww w .j a v a 2 s. co m*/ if (keepMinimalHtml) { cleanText = boilerPlateRemoval.getMinimalHtml(html, null); } else { cleanText = boilerPlateRemoval.getPlainText(html, null); } // write to the output file PrintWriter writer = new PrintWriter(outFile, "utf-8"); writer.write(cleanText); writer.close(); }
From source file:Main.java
/** * Run a command with the given data as input. *///from w ww .j a v a 2 s .c o m public static void systemIn(String command, String data) throws Exception { String cmd[] = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); PrintWriter w = new PrintWriter(p.getOutputStream()); w.print(data); w.flush(); w.close(); p.waitFor(); }
From source file:Main.java
/** * Run a command with the given data as input. *///ww w .j a v a 2 s .com public static void systemIn(String command, String data) throws Exception { String[] cmd = new String[3]; cmd[0] = System.getProperty("SHELL", "/bin/sh"); cmd[1] = "-c"; cmd[2] = command; Process p = Runtime.getRuntime().exec(cmd); PrintWriter w = new PrintWriter(p.getOutputStream()); w.print(data); w.flush(); w.close(); p.waitFor(); }
From source file:StringUtils.java
/** * Make a string representation of the exception. * @param e The exception to stringify/*from www . j a v a 2 s. c o m*/ * @return A string with exception name and call stack. */ public static String stringifyException(Throwable e) { StringWriter stm = new StringWriter(); PrintWriter wrt = new PrintWriter(stm); e.printStackTrace(wrt); wrt.close(); return stm.toString(); }
From source file:com.yolodata.tbana.testutils.FileTestUtils.java
public static boolean createFileWithContent(String filepath, String content) throws IOException { File f = new File(filepath); if (!f.createNewFile()) return false; PrintWriter pw = new PrintWriter(f); pw.write(content);/*from w w w. j a v a2 s . c o m*/ pw.close(); return true; }
From source file:StringUtil.java
/** * Get the stack trace of the supplied exception. * //from ww w. j a v a2s . co m * @param throwable the exception for which the stack trace is to be returned * @return the stack trace, or null if the supplied exception is null */ public static String getStackTrace(Throwable throwable) { if (throwable == null) return null; final ByteArrayOutputStream bas = new ByteArrayOutputStream(); final PrintWriter pw = new PrintWriter(bas); throwable.printStackTrace(pw); pw.close(); return bas.toString(); }
From source file:Main.java
public static <K, V> void printMap(Map<K, V> A, File file) throws FileNotFoundException, UnsupportedEncodingException { file.getParentFile().mkdirs();// w w w. j a v a 2 s . c o m PrintWriter p = new PrintWriter(file, "UTF-8"); for (K k : A.keySet()) p.println(k + "\t" + A.get(k)); p.close(); }
From source file:TheReplacements.java
public static void write(String fileName, String text) throws IOException { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); out.print(text);//from ww w .j a va2 s .c o m out.close(); }
From source file:Main.java
/** * Write a string to a file/*from w ww. j a va 2 s .co m*/ * @param content The string to write out * @param outputfile The file to which the string will be written */ public static void writeStringToFile(String content, File outputfile) { if (content != null && !content.equals("") && outputfile != null) { try { PrintWriter pwriter = new PrintWriter(new FileWriter(outputfile)); pwriter.print(content); pwriter.close(); } catch (IOException e) { e.printStackTrace(); } } }