List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file, Charset charset) throws IOException
From source file:MainClass.java
public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out, true); out.println("Hello, world"); }
From source file:PrintWriterDemo.java
public static void main(String args[]) { PrintWriter pw = new PrintWriter(System.out, true); pw.println("This is a string"); int i = -7;/*from ww w . ja v a2s. c om*/ pw.println(i); double d = 4.5e-7; pw.println(d); }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w . ja va 2 s. com*/ PrintWriter pw = new PrintWriter(System.out, true); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*w w w. ja va 2 s . c o m*/ PrintWriter pw = new PrintWriter(new File("c:/text.txt"), "ACSII"); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww.j a v a 2 s.co m*/ PrintWriter pw = new PrintWriter("c:/text.txt", "ACSII"); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String str = "???????"; try (PrintWriter out = new PrintWriter("output.txt", "UTF-8")) { out.write(str);//www. j ava 2s. c om } }
From source file:Main.java
public static void main(String[] args) { try {//from ww w . ja v a 2s . c o m PrintWriter pw = new PrintWriter(new FileWriter("c:/text.txt"), true); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { FileWriter fw = new FileWriter(args[0]); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw, false); pw.println(true);/*ww w . j av a 2 s. com*/ 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")); pw.close(); }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w.j av a 2 s. co m*/ char[] chars = new char[2]; chars[0] = '\u4F60'; chars[1] = '\u597D'; String encoding = "GB18030"; File textFile = new File("C:\\temp\\myFile.txt"); PrintWriter writer = new PrintWriter(textFile, encoding); writer.write(chars); writer.close(); // read back InputStreamReader reader = new InputStreamReader(new FileInputStream(textFile), encoding); char[] chars2 = new char[2]; reader.read(chars2); System.out.print(chars2[0]); System.out.print(chars2[1]); reader.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:MainClass.java
public static void main(String[] args) { try {/* w ww . j a va 2 s .c o m*/ char[] chars = new char[2]; chars[0] = '\u4F60'; chars[1] = '\u597D'; String encoding = "GB18030"; File textFile = new File("C:\\temp\\myFile.txt"); PrintWriter writer = new PrintWriter(textFile, encoding); writer.write(chars); writer.close(); // read back InputStreamReader reader = new InputStreamReader(new FileInputStream(textFile), encoding); char[] chars2 = new char[2]; reader.read(chars2); System.out.print(chars2[0]); System.out.print(chars2[1]); reader.close(); } catch (IOException e) { System.out.println(e.toString()); } }