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) {
    String s = "tutorial from java2s.com ";

    PrintWriter pw = new PrintWriter(System.out);

    // append the sequence
    pw.append(s);/*from www.  j  a v a 2 s  .  c  om*/

    // check if there is an error and flush
    System.out.println("" + pw.checkError());

}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    PrintWriter pw = new PrintWriter(System.out);

    // print string
    pw.print(s);/*from w  w  w . j a v a  2  s .c  o m*/

    // change the line twice
    pw.println();
    pw.println();

    // print another string
    pw.print("Two lines.");

    // flush the writer
    pw.flush();

}

From source file:MainClass.java

public static void main(String[] args) {
    try {// ww w .  j  a va2  s .  c  om
        PrintWriter pw = new PrintWriter("c:\\temp\\printWriterOutput.txt");
        pw.println("PrintWriter is easy to use.");
        pw.println(1234);
        pw.close();
    } catch (IOException e) {
    }
}

From source file:Main.java

public static void main(String[] args) {
    char[] c = { 'a', 'b', 'c', 'd', 'e', 'f' };

    PrintWriter pw = new PrintWriter(System.out);

    // write char
    pw.write(c, 1, 3);/* www .ja va 2s. c o  m*/
    pw.write(c, 3, 3);

    // flush the writer
    pw.flush();

}

From source file:Main.java

public static void main(String[] args) {
    String s = "Hello";
    try {//from ww w  .  ja v  a  2  s .c  om

        PrintWriter pw = new PrintWriter(System.out);

        // write strings
        pw.write(s);
        pw.write(" World");

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    Writer writer = new PrintWriter(System.out);

    try {/*from   www  .j  ava2 s. c  o  m*/
        // append a string
        writer.append(s);

        // flush the writer
        writer.flush();

        // append a new string
        writer.append("\nThis is an example");

        // flush and close the stream
        writer.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    Writer writer = new PrintWriter(System.out);

    try {//from w w  w .  j  a v a 2s  . c om
        // append a string
        writer.append(s);

        // flush the writer
        writer.flush();

        // append a new string in a new line
        writer.append("\nThis is an example");

        // flush the stream again
        writer.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    boolean bool = false;
    try {//from   w  ww .ja v  a 2  s.c o m

        PrintWriter pw = new PrintWriter(System.out);

        // print boolean
        pw.println(bool);
        pw.println(true);

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    CharSequence csq = "from java2s.com!";

    Writer writer = new PrintWriter(System.out);

    try {/*from  ww  w  . j av  a  2 s  . c  om*/
        writer.append("This is an example\n");

        // flush the writer
        writer.flush();

        // append a new sequence
        writer.append(csq, 2, 30);

        // flush the writer to see the result
        writer.flush();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    CharSequence csq = "from java2s.com!";

    Writer writer = new PrintWriter(System.out);

    try {// w  ww . j  av  a2s.c om
        // append a sequence and change line
        writer.append("This is an example\n");

        // flush the writer
        writer.flush();

        // append a new sequence
        writer.append(csq);

        // flush the writer to see the result
        writer.flush();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}