List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:Main.java
/** * make throwable to string.//from ww w . j a v a2 s .c o m */ public static String toString(Throwable throwable) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); printWriter.print(throwable.getClass().getName() + ": "); if (throwable.getMessage() != null) { printWriter.print(throwable.getMessage() + "\n"); } printWriter.println(); try { throwable.printStackTrace(printWriter); return stringWriter.toString(); } finally { printWriter.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); out.close();/*from w ww . j a v a 2s .c o m*/ }
From source file:PrintWriterDemo.java
public static void main() throws Exception { PrintWriter pw = new PrintWriter(new FileWriter("dice.txt")); for (int i = 1; i <= 1000; i++) { int die = (int) (1 + 6 * Math.random()); pw.print(die); pw.print(' '); if (i % 20 == 0) pw.println();// w w w .j a v a 2 s . c om } pw.println(); pw.close(); // Without this, the output file may be empty }
From source file:minij.codeemission.CodeEmitter.java
public static String emitCode(Configuration config, List<Fragment<List<Assem>>> assemFragments, MachineSpecifics machineSpecifics) throws CodeEmitterException { try {/*from w w w . j a v a 2s.c om*/ String assembly = machineSpecifics.printAssembly(assemFragments); ; if (config.codeEmission) { new File(FilenameUtils.getPath(config.outputFile)).mkdirs(); PrintWriter out = new PrintWriter(config.outputFile); out.print(assembly); out.close(); } Logger.logVerbosely("Successfully generated assembly"); if (config.printAssembly) { Logger.log(assembly); } return assembly; } catch (Exception e) { throw new CodeEmitterException("Failed to generate assembly", e); } }
From source file:Main.java
private static void renderErrorMessage(Exception e, Writer out) { PrintWriter pw = (out instanceof PrintWriter) ? (PrintWriter) out : new PrintWriter(out); pw.print("<u>"); pw.print(e.getMessage());/* ww w .java 2 s . co m*/ pw.print("</u> <pre>"); e.printStackTrace(pw); pw.print("</pre>"); }
From source file:mobisocial.musubi.ui.util.FeedHTML.java
public static void writeFooter(FileOutputStream fo) { PrintWriter w = new PrintWriter(fo); w.print("</body>"); w.print("</html>"); w.flush();/*from w w w. jav a 2 s. c om*/ }
From source file:Main.java
/** * Write attribute. If the value is null, no attribute is written. * /* w w w . ja v a 2s .com*/ * @param out * The writer. * @param name * The attribute name. * @param value * The attribute value. */ public static void writeAttribute(PrintWriter out, String name, String value) { if (value != null) { out.print(' '); out.print(name); out.print("=\""); writeCharacters(out, value); out.print("\""); } }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.registry.RegistryPersistence.java
@SuppressWarnings("unchecked") public static void storeRegistry(File registryFile, Map<String, IRegistrationData> registrationData) throws IOException { synchronized (lock) { JSONArray obj = new JSONArray(); for (Entry<String, IRegistrationData> entry : registrationData.entrySet()) { IRegistrationData rd = entry.getValue(); obj.add(rd);//from w w w . j av a 2s . c o m } PrintWriter pw = new PrintWriter(registryFile); pw.print(obj.toString()); pw.close(); LOG.info("Registry successfully saved to file " + registryFile); } }
From source file:mobisocial.musubi.ui.util.FeedHTML.java
public static void writeHeader(FileOutputStream fo, FeedManager feedManager, MFeed feed) { PrintWriter w = new PrintWriter(fo); w.print("<html>"); w.print("<head>"); w.print("<title>"); w.print(StringEscapeUtils.escapeHtml4(UiUtil.getFeedNameFromMembersList(feedManager, feed))); w.print("</title>"); w.print("</head>"); w.print("<body>"); w.print("<h1>"); w.print(StringEscapeUtils.escapeHtml4(UiUtil.getFeedNameFromMembersList(feedManager, feed))); w.print("</h1>"); w.flush();// w ww.ja v a2 s . c o m }
From source file:Main.java
public static void appendOneline(String fileName, String oneline) { PrintWriter out = null; try {/*from w w w .j a v a 2 s. c om*/ out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true))); out.print(oneline + "\n"); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { out.close(); } } }