Example usage for java.io PrintWriter PrintWriter

List of usage examples for java.io PrintWriter PrintWriter

Introduction

In this page you can find the example usage for java.io PrintWriter PrintWriter.

Prototype

public PrintWriter(File file) throws FileNotFoundException 

Source Link

Document

Creates a new PrintWriter, without automatic line flushing, with the specified file.

Usage

From source file:Main.java

public static void main(String[] args) {
    int i = 70;/*from w ww  . j av  a  2s .  com*/

    PrintWriter pw = new PrintWriter(System.out);

    // write integer as ASCII characters
    pw.write(i);
    pw.write(76);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    int i = 123;//w w w  . ja v a 2 s  .  co  m

    PrintWriter pw = new PrintWriter(System.out);

    // print int
    pw.println(i);
    pw.println(987);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'a';

    PrintWriter pw = new PrintWriter(System.out);

    // print string
    pw.println(c);//from  w w w. ja v  a  2s  . c  o  m
    pw.println('b');

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    char c = 'a';

    PrintWriter pw = new PrintWriter(System.out);

    // write char
    pw.write(c);//from www.  ja  v  a 2 s  .c  o  m
    pw.write('b');

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    try {//from w  ww  .  ja va 2  s .  co m
        PrintWriter pw = new PrintWriter("c:/text.txt");

        // 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  w w.j a  v  a2 s  .c  o  m
        PrintWriter pw = new PrintWriter(System.out);

        // 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 {//from w  ww . ja  v a 2s  . c om
        PrintWriter pw = new PrintWriter(new File("c:/text.txt"));

        // 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) {
    float f = 123.456f;

    PrintWriter pw = new PrintWriter(System.out);

    // print float
    pw.println(f);/*from  w ww . ja  va  2 s  . c  om*/
    pw.println(987.765f);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    double d = 123.456;

    PrintWriter pw = new PrintWriter(System.out);

    // print doubles
    pw.println(d);//ww w.  j ava  2s .  co  m
    pw.println(987.765);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    long l = 1234567890L;

    PrintWriter pw = new PrintWriter(System.out);

    // print long
    pw.println(l);/*from   w  ww  .j a  v a  2s  .  c o  m*/
    pw.println(987654321L);

    // flush the writer
    pw.flush();

}