Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I have a java app that uses log4j. Config: log4j.rootLogger=info, file log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=${user.home}/logs/app.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d [%t] %c %p %m%n So all the log statements are correctly appended to the file, but i am losing stdout ...
Why do certain streams need to be flushed (FileOutputStream and streams from Sockets) while the standard output stream does not? Every time someone uses the System.out PrintStream object, be it while calling println() or write(), they never flush the stream. However, other programmers habitually call flush() a PrintStream/PrintWriter with other streams. I've recently asked this question to s...
problem: I have a string containing special characters which i convert to bytes and vice versa..the conversion works properly on windows but on linux the special character is not converted properly.the default charset on linux is UTF-8 as seen with Charset.defaultCharset.getdisplayName() however if i run on linux with option -Dfile.encoding=ISO-8859-1 it works properly.. how to make it work ...
I'm familiar with printing time difference in milliseconds: long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time; But, is there a nice way print a complete time in a specified format (eg: HH:MM:SS) either using Apache Commons or even the dreaded platform API's Date/Time objects? In other words, what is the shor...
Some days ago I realized that PrintWriter (as well as PrintStream) never throw an IOException when writing, flushing or closing. Instead it sets an internal flag (trouble=true) when an error occurs. It's not possible to get the exact exception, but only if there was some exception (checkError()). My question is: why would one want to have such behavior? Isn't that bad API design?
I recently realized that I don't fully understand Java's string encoding process. Consider the following code: public class Main { public static void main(String[] args) { System.out.println(java.nio.charset.Charset.defaultCharset().name()); System.out.println("ack char: ^"); /* where ^ = 0x06, the ack char */ } } Since the control characters are interpreted diff...
We know that when we use objects in sysout(System.out.Println) statement internally it's toString method is called. and with primitive it directly prints. but when we use any Wrapper class type of objects is used say suppose Integer like following Integer i = new Integer(10) System.out.Println(i); is it toString() is responsible for printing it or Unboxing?
I want to work with SMP(Supplementary Multilingual Plane) in Java. Actually, I want to print a character whose codepoint is more than 0xFFFF. I used this line of code: int hexCodePoint = Character.toCodePoint('\uD801', '\uDC02' ); to have the codepoint of a special character. But how can I print this unicode character to the console? Thank you in advance for your help.
For example, Java's own String.format() supports a variable number of arguments. String.format("Hello %s! ABC %d!", "World", 123); //=> Hello World! ABC 123! How can I make my own function that accepts a variable number of arguments? Follow-up question: I'm really trying to make a convenience shortcut for this: System.out.println( String.format("...", a, b, c) ); So that I can call...
I have a Java stored procedure which fetches record from the table using Resultset object and creates a csv file. BLOB retBLOB = BLOB.createTemporary(conn, true, BLOB.DURATION_SESSION); retBLOB.open(BLOB.MODE_READWRITE); OutputStream bOut = retBLOB.setBinaryStream(0L); ZipOutputStream zipOut = new ZipOutputStream(bOut); PrintStream out = new PrintStream(zipOut,false,"UTF-8"); out.write('\ufeff...
may i know what is the difference between the two in java? i am reading a book and it can either use both of it to display strings.
What classes do you use to make string placeholders work? String template = "You have %1 tickets for %d", Brr object = new Brr(template, {new Integer(1), new Date()}); object.print();
Whenever I try to print the char arrays to the console, I'm getting the result in integer format, but whenever I try to print integer arrays to the console, I'm getting the result in hashcode format. Could anyone please tell me why? char[] arr={'4','5','6'}; System.out.println(arr); //456 int[] arr={4,5,6}; System.out.println(arr) //[I@3e25a5]
I came across this program and its not behaving in expected way. public class StringTest { public static void main(String[] args) { String s = "Hello world"; for(int i = 0 ; i < s.length() ; i++) { System.out.write(s.charAt(i)); } } } If we think it should print Hello world but it prints nothing. What is going...
Most of the IO operation requires try catch block or throws . Why is try catch or throws not required for System.out.print or println. If there is any exception inside these methods how would i know whats the exception and how to catch it.
If user passes a primitive type argument to println(), what exactly happens behind the scene? e.g. int i =1; System.out.println("My Int"+i); //and in System.out.println(i) How does it print "My Int 1" and "1", even though it needs a String object? updated.. What I think is AutoBoxing comes into play. Is that true, too?
It seems to me that PrintStream.print(Object x) and PrintStream.println(Object x) are identical to PrintStream.print(String x) and PrintStream.println(String x). Is there any obvious reason for having both? Are they different in any way? API-docs-readability? Efficiency? (With autoboxing, I suspect that even the print-methods taking primitives as arguments are redundant... however these metho...
Primitive question.. But how do I format string like this: "Step {1} of {2}" by substituting variables using Java? In C# it's easy.
I haven't had the chance to take any serious low-level programming courses in school. (I know I really should get going on learning the "behind-the-scenes" to be a better programmer.) I appreciate the conveniences of Java, including the ability to stick anything into a System.out.print statement. However, is there any reason why you would want to use System.out.printf instead? Also, should I ...
I'm creating a java program that creates a file and fills it with data in string form with each field in the record limited to a specific length. What I think I need to do is to create a class that has a string for the data field and a length specifying the length of the string. And then somehow restrict it so that the string never exceeds this length, either by bailing, padding with whitespac...
I have a problem which I have to print with long decimal places. such as 1/3 = 0.33333333333333333333333333333333333333 (very very long) when using C, we can use printf("%.30f", a); but I don't know what to do using Java
   /*
    * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    *
    * This code is free software; you can redistribute it and/or modify it
    * under the terms of the GNU General Public License version 2 only, as
    * published by the Free Software Foundation.  Sun designates this
    * particular file as subject to the "Classpath" exception as provided
    * by Sun in the LICENSE file that accompanied this code.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   * CA 95054 USA or visit www.sun.com if you need additional information or
   * have any questions.
   */
  
  package java.io;
  
  import java.util.Locale;


A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Two other features are provided as well. Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.

All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.

Author(s):
Frank Yellin
Mark Reinhold
Since:
JDK1.0
  
  
  public class PrintStream extends FilterOutputStream
      implements AppendableCloseable
  {
  
      private boolean autoFlush = false;
      private boolean trouble = false;
      private Formatter formatter;

    
Track both the text- and character-output streams, so that their buffers can be flushed without flushing the entire stream.
  
      private BufferedWriter textOut;
      private OutputStreamWriter charOut;

    
Creates a new print stream. This stream will not flush automatically.

Parameters:
out The output stream to which values and objects will be printed
See also:
java.io.PrintWriter.PrintWriter.(java.io.OutputStream)
  
      public PrintStream(OutputStream out) {
          this(outfalse);
      }
  
      /* Initialization is factored into a private constructor (note the swapped
       * parameters so that this one isn't confused with the public one) and a
       * separate init method so that the following two public constructors can
       * share code.  We use a separate init method so that the constructor that
       * takes an encoding will throw an NPE for a null stream before it throws
       * an UnsupportedEncodingException for an unsupported encoding.
       */
  
      private PrintStream(boolean autoFlushOutputStream out)
      {
          super(out);
          if (out == null)
              throw new NullPointerException("Null output stream");
          this. = autoFlush;
      }
  
      private void init(OutputStreamWriter osw) {
          this. = osw;
         this. = new BufferedWriter(osw);
     }

    
Creates a new print stream.

Parameters:
out The output stream to which values and objects will be printed
autoFlush A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
See also:
java.io.PrintWriter.PrintWriter.(java.io.OutputStream,boolean)
 
     public PrintStream(OutputStream outboolean autoFlush) {
         this(autoFlushout);
         init(new OutputStreamWriter(this));
     }

    
Creates a new print stream.

Parameters:
out The output stream to which values and objects will be printed
autoFlush A boolean; if true, the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
encoding The name of a supported character encoding
Throws:
UnsupportedEncodingException If the named encoding is not supported
Since:
1.4
 
     public PrintStream(OutputStream outboolean autoFlushString encoding)
         throws UnsupportedEncodingException
     {
         this(autoFlushout);
         init(new OutputStreamWriter(thisencoding));
     }

    
Creates a new print stream, without automatic line flushing, with the specified file name. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the default charset for this instance of the Java virtual machine.

Parameters:
fileName The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
Throws:
FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
java.lang.SecurityException If a security manager is present and java.lang.SecurityManager.checkWrite(java.io.FileDescriptor) denies write access to the file
Since:
1.5
 
     public PrintStream(String fileNamethrows FileNotFoundException {
         this(falsenew FileOutputStream(fileName));
         init(new OutputStreamWriter(this));
     }

    
Creates a new print stream, without automatic line flushing, with the specified file name and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters:
fileName The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
csn The name of a supported charset
Throws:
FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
java.lang.SecurityException If a security manager is present and java.lang.SecurityManager.checkWrite(java.io.FileDescriptor) denies write access to the file
UnsupportedEncodingException If the named charset is not supported
Since:
1.5
 
     public PrintStream(String fileNameString csn)
     {
         this(falsenew FileOutputStream(fileName));
         init(new OutputStreamWriter(thiscsn));
     }

    
Creates a new print stream, without automatic line flushing, with the specified file. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the java.nio.charset.Charset.defaultCharset() for this instance of the Java virtual machine.

Parameters:
file The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
Throws:
FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
java.lang.SecurityException If a security manager is present and java.lang.SecurityManager.checkWrite(java.io.FileDescriptor) denies write access to the file
Since:
1.5
 
     public PrintStream(File filethrows FileNotFoundException {
         this(falsenew FileOutputStream(file));
         init(new OutputStreamWriter(this));
     }

    
Creates a new print stream, without automatic line flushing, with the specified file and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters:
file The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
csn The name of a supported charset
Throws:
FileNotFoundException If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
java.lang.SecurityException If a security manager is presentand java.lang.SecurityManager.checkWrite(java.io.FileDescriptor) denies write access to the file
UnsupportedEncodingException If the named charset is not supported
Since:
1.5
 
     public PrintStream(File fileString csn)
     {
         this(falsenew FileOutputStream(file));
         init(new OutputStreamWriter(thiscsn));
     }

    
Check to make sure that the stream has not been closed
 
     private void ensureOpen() throws IOException {
         if ( == null)
             throw new IOException("Stream closed");
     }

    
Flushes the stream. This is done by writing any buffered output bytes to the underlying output stream and then flushing that stream.

 
     public void flush() {
         synchronized (this) {
             try {
                 ensureOpen();
                 .flush();
             }
             catch (IOException x) {
                  = true;
             }
         }
     }
 
     private boolean closing = false/* To avoid recursive closing */

    
Closes the stream. This is done by flushing the stream and then closing the underlying output stream.

 
     public void close() {
         synchronized (this) {
             if (! ) {
                  = true;
                 try {
                     .close();
                     .close();
                 }
                 catch (IOException x) {
                      = true;
                 }
                  = null;
                  = null;
                  = null;
             }
         }
     }

    
Flushes the stream and checks its error state. The internal error state is set to true when the underlying output stream throws an IOException other than InterruptedIOException, and when the setError method is invoked. If an operation on the underlying output stream throws an InterruptedIOException, then the PrintStream converts the exception back into an interrupt by doing:
     Thread.currentThread().interrupt();
 
or the equivalent.

Returns:
true if and only if this stream has encountered an IOException other than InterruptedIOException, or the setError method has been invoked
 
     public boolean checkError() {
         if ( != null)
             flush();
         if ( instanceof java.io.PrintStream) {
             PrintStream ps = (PrintStream;
             return ps.checkError();
         }
         return ;
     }

    
Sets the error state of the stream to true.

This method will cause subsequent invocations of checkError() to return true until clearError() is invoked.

Since:
JDK1.1
 
     protected void setError() {
          = true;
     }

    
Clears the internal error state of this stream.

This method will cause subsequent invocations of checkError() to return false until another write operation fails and invokes setError().

Since:
1.6
 
     protected void clearError() {
          = false;
     }
 
     /*
      * Exception-catching, synchronized output operations,
      * which also implement the write() methods of OutputStream
      */

    
Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked.

Note that the byte is written as given; to write a character that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods.

Parameters:
b The byte to be written
See also:
print(char)
println(char)
 
     public void write(int b) {
         try {
             synchronized (this) {
                 ensureOpen();
                 .write(b);
                 if ((b == '\n') && )
                     .flush();
             }
         }
         catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         }
         catch (IOException x) {
              = true;
         }
     }

    
Writes len bytes from the specified byte array starting at offset off to this stream. If automatic flushing is enabled then the flush method will be invoked.

Note that the bytes will be written as given; to write characters that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods.

Parameters:
buf A byte array
off Offset from which to start taking bytes
len Number of bytes to write
 
     public void write(byte buf[], int offint len) {
         try {
             synchronized (this) {
                 ensureOpen();
                 .write(bufofflen);
                 if ()
                     .flush();
             }
         }
         catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         }
         catch (IOException x) {
              = true;
         }
     }
 
     /*
      * The following private methods on the text- and character-output streams
      * always flush the stream buffers, so that writes to the underlying byte
      * stream occur as promptly as with the original PrintStream.
      */
 
     private void write(char buf[]) {
         try {
             synchronized (this) {
                 ensureOpen();
                 .write(buf);
                 .flushBuffer();
                 .flushBuffer();
                 if () {
                     for (int i = 0; i < buf.lengthi++)
                         if (buf[i] == '\n')
                             .flush();
                 }
             }
         }
         catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         }
         catch (IOException x) {
              = true;
         }
     }
 
     private void write(String s) {
         try {
             synchronized (this) {
                 ensureOpen();
                 .write(s);
                 .flushBuffer();
                 .flushBuffer();
                 if ( && (s.indexOf('\n') >= 0))
                     .flush();
             }
         }
         catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         }
         catch (IOException x) {
              = true;
         }
     }
 
     private void newLine() {
         try {
             synchronized (this) {
                 ensureOpen();
                 .newLine();
                 .flushBuffer();
                 .flushBuffer();
                 if ()
                     .flush();
             }
         }
         catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         }
         catch (IOException x) {
              = true;
         }
     }
 
     /* Methods that do not terminate lines */

    
Prints a boolean value. The string produced by java.lang.String.valueOf(boolean) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
b The boolean to be printed
 
     public void print(boolean b) {
         write(b ? "true" : "false");
     }

    
Prints a character. The character is translated into one or more bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
c The char to be printed
 
     public void print(char c) {
         write(String.valueOf(c));
     }

    
Prints an integer. The string produced by java.lang.String.valueOf(int) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
i The int to be printed
See also:
java.lang.Integer.toString(int)
 
     public void print(int i) {
         write(String.valueOf(i));
     }

    
Prints a long integer. The string produced by java.lang.String.valueOf(long) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
l The long to be printed
See also:
java.lang.Long.toString(long)
 
     public void print(long l) {
         write(String.valueOf(l));
     }

    
Prints a floating-point number. The string produced by java.lang.String.valueOf(float) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
f The float to be printed
See also:
java.lang.Float.toString(float)
 
     public void print(float f) {
         write(String.valueOf(f));
     }

    
Prints a double-precision floating-point number. The string produced by java.lang.String.valueOf(double) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
d The double to be printed
See also:
java.lang.Double.toString(double)
 
     public void print(double d) {
         write(String.valueOf(d));
     }

    
Prints an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
s The array of chars to be printed
Throws:
java.lang.NullPointerException If s is null
 
     public void print(char s[]) {
         write(s);
     }

    
Prints a string. If the argument is null then the string "null" is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
s The String to be printed
 
     public void print(String s) {
         if (s == null) {
             s = "null";
         }
         write(s);
     }

    
Prints an object. The string produced by the java.lang.String.valueOf(java.lang.Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

Parameters:
obj The Object to be printed
See also:
java.lang.Object.toString()
 
     public void print(Object obj) {
         write(String.valueOf(obj));
     }
 
 
     /* Methods that do terminate lines */

    
Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').
 
     public void println() {
         newLine();
     }

    
Prints a boolean and then terminate the line. This method behaves as though it invokes print(boolean) and then println().

Parameters:
x The boolean to be printed
 
     public void println(boolean x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints a character and then terminate the line. This method behaves as though it invokes print(char) and then println().

Parameters:
x The char to be printed.
 
     public void println(char x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints an integer and then terminate the line. This method behaves as though it invokes print(int) and then println().

Parameters:
x The int to be printed.
 
     public void println(int x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints a long and then terminate the line. This method behaves as though it invokes print(long) and then println().

Parameters:
x a The long to be printed.
 
     public void println(long x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints a float and then terminate the line. This method behaves as though it invokes print(float) and then println().

Parameters:
x The float to be printed.
 
     public void println(float x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints a double and then terminate the line. This method behaves as though it invokes print(double) and then println().

Parameters:
x The double to be printed.
 
     public void println(double x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().

Parameters:
x an array of chars to print.
 
     public void println(char x[]) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints a String and then terminate the line. This method behaves as though it invokes print(java.lang.String) and then println().

Parameters:
x The String to be printed.
 
     public void println(String x) {
         synchronized (this) {
             print(x);
             newLine();
         }
     }

    
Prints an Object and then terminate the line. This method calls at first String.valueOf(x) to get the printed object's string value, then behaves as though it invokes print(java.lang.String) and then println().

Parameters:
x The Object to be printed.
 
     public void println(Object x) {
         String s = String.valueOf(x);
         synchronized (this) {
             print(s);
             newLine();
         }
     }


    
A convenience method to write a formatted string to this output stream using the specified format string and arguments.

An invocation of this method of the form out.printf(format, args) behaves in exactly the same way as the invocation

     out.format(format, args) 

Parameters:
format A format string as described in Format string syntax
args Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
Returns:
This output stream
Throws:
IllegalFormatException If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
java.lang.NullPointerException If the format is null
Since:
1.5
 
     public PrintStream printf(String formatObject ... args) {
         return format(formatargs);
     }

    
A convenience method to write a formatted string to this output stream using the specified format string and arguments.

An invocation of this method of the form out.printf(l, format, args) behaves in exactly the same way as the invocation

     out.format(l, format, args) 

Parameters:
l The locale to apply during formatting. If l is null then no localization is applied.
format A format string as described in Format string syntax
args Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
Returns:
This output stream
Throws:
IllegalFormatException If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
java.lang.NullPointerException If the format is null
Since:
1.5
 
     public PrintStream printf(Locale lString formatObject ... args) {
         return format(lformatargs);
     }

    
Writes a formatted string to this output stream using the specified format string and arguments.

The locale always used is the one returned by java.util.Locale.getDefault(), regardless of any previous invocations of other formatting methods on this object.

Parameters:
format A format string as described in Format string syntax
args Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
Returns:
This output stream
Throws:
IllegalFormatException If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
java.lang.NullPointerException If the format is null
Since:
1.5
 
     public PrintStream format(String formatObject ... args) {
         try {
             synchronized (this) {
                 ensureOpen();
                 if (( == null)
                     || (.locale() != Locale.getDefault()))
                      = new Formatter((Appendablethis);
                 .format(Locale.getDefault(), formatargs);
             }
         } catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         } catch (IOException x) {
              = true;
         }
         return this;
     }

    
Writes a formatted string to this output stream using the specified format string and arguments.

Parameters:
l The locale to apply during formatting. If l is null then no localization is applied.
format A format string as described in Format string syntax
args Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
Returns:
This output stream
Throws:
IllegalFormatException If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
java.lang.NullPointerException If the format is null
Since:
1.5
 
     public PrintStream format(Locale lString formatObject ... args) {
         try {
             synchronized (this) {
                 ensureOpen();
                 if (( == null)
                     || (.locale() != l))
                      = new Formatter(thisl);
                 .format(lformatargs);
             }
         } catch (InterruptedIOException x) {
             Thread.currentThread().interrupt();
         } catch (IOException x) {
              = true;
        }
        return this;
    }

    
Appends the specified character sequence to this output stream.

An invocation of this method of the form out.append(csq) behaves in exactly the same way as the invocation

     out.print(csq.toString()) 

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking then toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Parameters:
csq The character sequence to append. If csq is null, then the four characters "null" are appended to this output stream.
Returns:
This output stream
Since:
1.5
    public PrintStream append(CharSequence csq) {
        if (csq == null)
            print("null");
        else
            print(csq.toString());
        return this;
    }

    
Appends a subsequence of the specified character sequence to this output stream.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

     out.print(csq.subSequence(start, end).toString()) 

Parameters:
csq The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
start The index of the first character in the subsequence
end The index of the character following the last character in the subsequence
Returns:
This output stream
Throws:
java.lang.IndexOutOfBoundsException If start or end are negative, start is greater than end, or end is greater than csq.length()
Since:
1.5
    public PrintStream append(CharSequence csqint startint end) {
        CharSequence cs = (csq == null ? "null" : csq);
        write(cs.subSequence(startend).toString());
        return this;
    }

    
Appends the specified character to this output stream.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

     out.print(c) 

Parameters:
c The 16-bit character to append
Returns:
This output stream
Since:
1.5
    public PrintStream append(char c) {
        print(c);
        return this;
    }
New to GrepCode? Check out our FAQ X