< prev index next >

src/java.base/share/classes/java/io/PrintWriter.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 687     }
 688 
 689     /**
 690      * Prints an object.  The string produced by the {@link
 691      * java.lang.String#valueOf(Object)} method is translated into bytes
 692      * according to the platform's default character encoding, and these bytes
 693      * are written in exactly the manner of the {@link #write(int)}
 694      * method.
 695      *
 696      * @param      obj   The {@code Object} to be printed
 697      * @see        java.lang.Object#toString()
 698      */
 699     public void print(Object obj) {
 700         write(String.valueOf(obj));
 701     }
 702 
 703     /* Methods that do terminate lines */
 704 
 705     /**
 706      * Terminates the current line by writing the line separator string.  The
 707      * line separator is {@link System#lineSeparator()} and is not necessarily
 708      * a single newline character ({@code '\n'}).

 709      */
 710     public void println() {
 711         newLine();
 712     }
 713 
 714     /**
 715      * Prints a boolean value and then terminates the line.  This method behaves
 716      * as though it invokes {@link #print(boolean)} and then
 717      * {@link #println()}.
 718      *
 719      * @param x the {@code boolean} value to be printed
 720      */
 721     public void println(boolean x) {
 722         synchronized (lock) {
 723             print(x);
 724             println();
 725         }
 726     }
 727 
 728     /**


   1 /*
   2  * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 687     }
 688 
 689     /**
 690      * Prints an object.  The string produced by the {@link
 691      * java.lang.String#valueOf(Object)} method is translated into bytes
 692      * according to the platform's default character encoding, and these bytes
 693      * are written in exactly the manner of the {@link #write(int)}
 694      * method.
 695      *
 696      * @param      obj   The {@code Object} to be printed
 697      * @see        java.lang.Object#toString()
 698      */
 699     public void print(Object obj) {
 700         write(String.valueOf(obj));
 701     }
 702 
 703     /* Methods that do terminate lines */
 704 
 705     /**
 706      * Terminates the current line by writing the line separator string.  The
 707      * line separator string is defined by the system property
 708      * {@code line.separator}, and is not necessarily a single newline
 709      * character ({@code '\n'}).
 710      */
 711     public void println() {
 712         newLine();
 713     }
 714 
 715     /**
 716      * Prints a boolean value and then terminates the line.  This method behaves
 717      * as though it invokes {@link #print(boolean)} and then
 718      * {@link #println()}.
 719      *
 720      * @param x the {@code boolean} value to be printed
 721      */
 722     public void println(boolean x) {
 723         synchronized (lock) {
 724             print(x);
 725             println();
 726         }
 727     }
 728 
 729     /**


< prev index next >