List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file, Charset charset) throws IOException
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:Main.java
public static void hexaDumpHangul(OutputStream outStream, byte[] data, int len, String desc) { //if (desc.compareToIgnoreCase("outflow")==0) return ; PrintWriter out = new PrintWriter(outStream, true); int index = 0; out.println("[[LEN=" + len + "]/[" + desc + "][" + getTime() + "]]"); for (int i = 0; i < len; i++) { index = (i + 1) % 16;//from w ww .j a va 2 s . com out.print(byteToHexa(data[i]) + " "); if (index == 0) { out.println(" " + new String(data, (i + 1) - 16, 16)); } } if (index != 0) { for (int i = 0; i < 16 - index; i++) out.print(" " + " "); out.println(" " + new String(data, data.length - index, index)); } }
From source file:latexstudio.editor.files.FileService.java
public static void writeToFile(String filename, String content) { try (PrintWriter writer = new PrintWriter(filename, "UTF-8")) { writer.print(content);//from w ww . j a va 2 s .c om } catch (FileNotFoundException | UnsupportedEncodingException ex) { //Should never happen Exceptions.printStackTrace(ex); } }
From source file:edu.usc.qspr.Main.java
/** * The main method./*from w w w .j a va2 s . com*/ * * @param args the arguments * @throws IOException */ public static void main(String[] args) throws IOException { double result; long start = System.currentTimeMillis(); //TODO: to be commented // args = new String("-i sample_inputs/5-1-3.qasm -f sample_inputs/fabric.ql -o output -p baseline -s 21 -v").split(" "); // args = new String("-i ../sample_inputs/5-1-3.qasm -f ../sample_inputs/fabric.ql -p mvfb -s 2 -v").split(" "); parseInputs(args); if (RuntimeConfig.OUTPUT_TO_FILE) { outputFile = new PrintWriter(new BufferedWriter(new FileWriter(outputFileAddr, false)), true); } else { //writing to stdout outputFile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); } //Prints the current working directory if (RuntimeConfig.DEBUG) System.out.println("Current directory: " + System.getProperty("user.dir")); layout = LayoutParser.LayoutParser(fabricFileAddr); qasm = QASMParser.QASMParser(qasmFileAddr); eds = new EventDrivenSimulator(layout, qasm.getCommandsList(), outputFile); if (placementMethod.compareTo("center") == 0) { result = center(); } else if (placementMethod.compareTo("baseline") == 0) { result = baseLine(); } else if (placementMethod.compareTo("mc") == 0) { result = mc(m, false); } else { //default is mvfb result = mvfb(m); } outputFile.println("------------------------------------"); outputFile.println("Execution latency: " + result + " us"); long end = System.currentTimeMillis(); outputFile.println("QSPR runtime " + (end - start) + " ms"); if (RuntimeConfig.OUTPUT_TO_FILE) { outputFile.close(); } else { outputFile.flush(); } if (RuntimeConfig.VERBOSE) { System.out.println("Done."); } }
From source file:WriteFile.java
private static PrintWriter openWriter(String name) { try {//from w w w .j a v a 2s .c o m File file = new File(name); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)), true); return out; } catch (IOException e) { System.out.println("I/O Error"); System.exit(0); } return null; }
From source file:com.nuance.expertassistant.ContentExtractor.java
public static void startDocument(String Title, String Filepath) { try {//w w w. j a v a 2 s . com writer = new PrintWriter(Filepath, "UTF-8"); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<document xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + " xmlns:fn=\"http://www.w3.org/2005/xpath-functions\"\n" + " xmlns:xdt=\"http://www.w3.org/2005/xpath-datatypes\"\n" + " docid=\"a382247e\"\n" + " title=\"" + Title + "\">"); } catch (final FileNotFoundException ex) { Logger.getLogger(ContentExtractor.class.getName()).log(Level.SEVERE, null, ex); } catch (final UnsupportedEncodingException ex) { Logger.getLogger(ContentExtractor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static String getStackTrace(Throwable t) { StringWriter stringWritter = new StringWriter(); PrintWriter printWritter = new PrintWriter(stringWritter, true); t.printStackTrace(printWritter);// w ww . j av a2 s.c om printWritter.flush(); stringWritter.flush(); return stringWritter.toString(); }
From source file:com.kaaprotech.satu.util.CmdLineUtil.java
public static String getCommandLineUsageMessage() { final HelpFormatter formatter = new HelpFormatter(); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw, true); pw.println();//from w ww . j a va 2s.co m formatter.printHelp(pw, 120, "Satu", null, getOptions(), 2, 10, null); return sw.getBuffer().toString(); }
From source file:Main.java
/** * Returns the output of printStackTrace as a String. * * @param e A Throwable./*from w ww.j a v a2 s . com*/ * @return A String. */ public static final String stackTrace(Throwable e) { String foo = null; try { // And show the Error Screen. ByteArrayOutputStream ostr = new ByteArrayOutputStream(); e.printStackTrace(new PrintWriter(ostr, true)); foo = ostr.toString(); } catch (Exception f) { // Do nothing. } return foo; }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Locale locale;//from w ww .ja v a2s . c o m DateFormat full; try { res.setContentType("text/plain; charset=UTF-8"); //PrintWriter out = res.getWriter(); PrintWriter out = new PrintWriter(new OutputStreamWriter(res.getOutputStream(), "UTF8"), true); locale = new Locale("en", "US"); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In English appropriate for the US:"); out.println("Hello World!"); out.println(full.format(new Date())); out.println(); locale = new Locale("es", ""); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("En Espa\u00f1ol:"); out.println("\u00a1Hola Mundo!"); out.println(full.format(new Date())); out.println(); locale = new Locale("ja", ""); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Japanese:"); out.println("\u4eca\u65e5\u306f\u4e16\u754c"); out.println(full.format(new Date())); out.println(); locale = new Locale("zh", ""); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Chinese:"); out.println("\u4f60\u597d\u4e16\u754c"); out.println(full.format(new Date())); out.println(); locale = new Locale("ko", ""); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Korean:"); out.println("\uc548\ub155\ud558\uc138\uc694\uc138\uacc4"); out.println(full.format(new Date())); out.println(); locale = new Locale("ru", ""); full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Russian (Cyrillic):"); out.print("\u0417\u0434\u0440\u0430\u0432\u0441\u0442"); out.println("\u0432\u0443\u0439, \u041c\u0438\u0440"); out.println(full.format(new Date())); out.println(); } catch (Exception e) { e.printStackTrace(); } }