Class Out
- Object
-
- Out
-
public class Out extends Object
TheOut
data type provides methods for writing strings and numbers to various output streams, including standard output, file, and sockets.For additional documentation, see Section 3.1 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
-
-
Constructor Summary
Constructors Constructor Description Out()
Initializes an output stream from standard output.Out(OutputStream os)
Initializes an output stream from aOutputStream
.Out(String filename)
Initializes an output stream from a file.Out(Socket socket)
Initializes an output stream from a socket.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the output stream.static void
main(String[] args)
A test client.void
print()
Flushes this output stream.void
print(boolean x)
Prints a boolean to this output stream and flushes this output stream.void
print(byte x)
Prints a byte to this output stream and flushes this output stream.void
print(char x)
Prints a character to this output stream and flushes this output stream.void
print(double x)
Prints a double to this output stream and flushes this output stream.void
print(float x)
Prints a float to this output stream and flushes this output stream.void
print(int x)
Prints an integer to this output stream and flushes this output stream.void
print(long x)
Prints a long integer to this output stream and flushes this output stream.void
print(Object x)
Prints an object to this output stream and flushes this output stream.void
printf(String format, Object... args)
Prints a formatted string to this output stream, using the specified format string and arguments, and then flushes this output stream.void
printf(Locale locale, String format, Object... args)
Prints a formatted string to this output stream, using the specified locale, format string, and arguments, and then flushes this output stream.void
println()
Terminates the current line by printing the line-separator string.void
println(boolean x)
Prints a boolean to this output stream and then terminates the line.void
println(byte x)
Prints a byte to this output stream and then terminates the line.void
println(char x)
Prints a character to this output stream and then terminates the line.void
println(double x)
Prints a double to this output stream and then terminates the line.void
println(float x)
Prints a float to this output stream and then terminates the line.void
println(int x)
Prints an integer to this output stream and then terminates the line.void
println(long x)
Prints a long to this output stream and then terminates the line.void
println(Object x)
Prints an object to this output stream and then terminates the line.
-
-
-
Constructor Detail
-
Out
public Out(OutputStream os)
Initializes an output stream from aOutputStream
.- Parameters:
os
- theOutputStream
-
Out
public Out()
Initializes an output stream from standard output.
-
Out
public Out(Socket socket)
Initializes an output stream from a socket.- Parameters:
socket
- the socket- Throws:
IllegalArgumentException
- iffilename
isnull
IllegalArgumentException
- if cannot create output stream from socket
-
Out
public Out(String filename)
Initializes an output stream from a file.- Parameters:
filename
- the name of the file- Throws:
IllegalArgumentException
- iffilename
isnull
IllegalArgumentException
- iffilename
is the empty stringIllegalArgumentException
- if cannot write the filefilename
-
-
Method Detail
-
close
public void close()
Closes the output stream.
-
println
public void println()
Terminates the current line by printing the line-separator string.
-
println
public void println(Object x)
Prints an object to this output stream and then terminates the line.- Parameters:
x
- the object to print
-
println
public void println(boolean x)
Prints a boolean to this output stream and then terminates the line.- Parameters:
x
- the boolean to print
-
println
public void println(char x)
Prints a character to this output stream and then terminates the line.- Parameters:
x
- the character to print
-
println
public void println(double x)
Prints a double to this output stream and then terminates the line.- Parameters:
x
- the double to print
-
println
public void println(float x)
Prints a float to this output stream and then terminates the line.- Parameters:
x
- the float to print
-
println
public void println(int x)
Prints an integer to this output stream and then terminates the line.- Parameters:
x
- the integer to print
-
println
public void println(long x)
Prints a long to this output stream and then terminates the line.- Parameters:
x
- the long to print
-
println
public void println(byte x)
Prints a byte to this output stream and then terminates the line.To write binary data, see
BinaryOut
.- Parameters:
x
- the byte to print
-
print
public void print()
Flushes this output stream.
-
print
public void print(Object x)
Prints an object to this output stream and flushes this output stream.- Parameters:
x
- the object to print
-
print
public void print(boolean x)
Prints a boolean to this output stream and flushes this output stream.- Parameters:
x
- the boolean to print
-
print
public void print(char x)
Prints a character to this output stream and flushes this output stream.- Parameters:
x
- the character to print
-
print
public void print(double x)
Prints a double to this output stream and flushes this output stream.- Parameters:
x
- the double to print
-
print
public void print(float x)
Prints a float to this output stream and flushes this output stream.- Parameters:
x
- the float to print
-
print
public void print(int x)
Prints an integer to this output stream and flushes this output stream.- Parameters:
x
- the integer to print
-
print
public void print(long x)
Prints a long integer to this output stream and flushes this output stream.- Parameters:
x
- the long integer to print
-
print
public void print(byte x)
Prints a byte to this output stream and flushes this output stream.- Parameters:
x
- the byte to print
-
printf
public void printf(String format, Object... args)
Prints a formatted string to this output stream, using the specified format string and arguments, and then flushes this output stream.- Parameters:
format
- the format stringargs
- the arguments accompanying the format string
-
printf
public void printf(Locale locale, String format, Object... args)
Prints a formatted string to this output stream, using the specified locale, format string, and arguments, and then flushes this output stream.- Parameters:
locale
- the localeformat
- the format stringargs
- the arguments accompanying the format string
-
main
public static void main(String[] args)
A test client.- Parameters:
args
- the command-line arguments
-
-