List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com "; try {/*from w ww. ja v a 2 s .c o m*/ PrintWriter pw = new PrintWriter(System.out); // append the sequence pw.append(s); // flush the writer pw.flush(); // print another string pw.println("This is an example"); // flush the writer again pw.flush(); // close the writer pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; try {//from w w w. j av a 2s . com PrintWriter pw = new PrintWriter(System.out); // %s indicates a string will be placed there, which is s pw.printf("This is a %s program", s); // flush the writer pw.flush(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; try {//www.j a v a 2 s. c o m PrintWriter pw = new PrintWriter(System.out); // printf text with specified locale. // %s indicates a string will be placed there, which is s pw.printf(Locale.UK, "This is a %s program", s); // flush the writer pw.flush(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; try {//from w w w. j av a 2s . c om PrintWriter pw = new PrintWriter(System.out); // format text with specified locale. // %s indicates a string will be placed there, which is s pw.format(Locale.UK, "This is a %s program", s); // flush the writer pw.flush(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char[] c1 = { 'a', 'b', 'c', 'd', 'e' }; char[] c2 = { 'f', 'g', 'h', 'i', 'j' }; PrintWriter pw = new PrintWriter(System.out); // print char array pw.println(c1);//from www . j av a 2s .com pw.println(c2); // flush the writer pw.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); PrintWriter writer = new PrintWriter(System.out); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "150"); prop.put("tutorial", "java2s.com"); prop.put("Runnable", "true"); // print the list with a PrintWriter object prop.list(writer);//from w ww . j a va2s. c o m // flush the stream writer.flush(); }
From source file:HTMLDemo.java
public static void main(String[] a) throws IOException { PrintWriter pw = new PrintWriter(new FileWriter("test.html")); DecimalFormat ff = new DecimalFormat("#0"), cf = new DecimalFormat("0.0"); pw.println("<TABLE BORDER><TR><TH>Fahrenheit<TH>Celsius</TR>"); for (double f = 100; f <= 400; f += 10) { double c = 5 * (f - 32) / 9; pw.println("<TR ALIGN=RIGHT><TD>" + ff.format(f) + "<TD>" + cf.format(c)); }// w ww . j a va 2s . c o m pw.println("</TABLE>"); pw.close(); // Without this, the output file may be empty }
From source file:Main.java
public static void main(String[] args) { char[] c1 = { 'h', 'e', 'l', 'l', 'o' }; char[] c2 = { 'w', 'o', 'r', 'l', 'd' }; Writer writer = new PrintWriter(System.out); try {//from w ww . ja v a2 s. c om // write a char array writer.write(c1); // flush the writer writer.flush(); // write a new char array writer.write(c2); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] argv) throws FileNotFoundException { Throwable t = new Exception("from java2s.com"); t.printStackTrace(new PrintWriter("file.name")); }
From source file:MainClass.java
public static void main(String args[]) { try {//from w ww. ja v a 2 s .c o m PrintWriter pw = new PrintWriter(System.out); // Experiment with some methods pw.println(true); pw.println('A'); pw.println(500); pw.println(40000L); pw.println(45.67f); pw.println(45.67); pw.println("Hello"); pw.println(new Integer("99")); // Close print writer pw.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }