Java.io.outputstream.PrintStream: Print Stream

Source: Internet
Author: User

Java.io.outputstream. PrintStream : Print Flow

1: Provides more features, such as printing methods. You can print any type of data directly.

2: It has an automatic refresh mechanism that creates the object, specifies parameters, and can be automatically refreshed for the specified method.

3: It uses the native default character encoding.

4: The Print method of the stream does not throw IOException.

The constructor for the object.

PrintStream (File file): Creates a new print stream with the specified file and without automatic row refresh.

PrintStream (file file, String CSN): Creates a new print stream with the specified file name and character set without automatic row refresh.

PrintStream (OutputStream out): Creates a new print stream.

PrintStream (OutputStream out, Boolean AutoFlush): Creates a new print stream.

PrintStream (OutputStream out, Boolean autoflush, String encoding): Creates a new print stream.

PrintStream (String fileName): Creates a new print stream with the specified file name and without automatic row refresh.

PrintStream (String fileName, String CSN)

PrintStream you can manipulate the purpose:1:file object. 2: String path. 3: Byte output stream.

Only the first two JDK1.5 versions appear. And when manipulating a text file, you can specify a character encoding.

When the destination is a byte output stream, if you use the Println method, you can add a true parameter on the PrintStream object. This allows for an automatic refresh of the println method instead of waiting for the buffer to be full and then refreshed. The final print method turns specific data into strings, and all of the IO exceptions are handled internally.

Now that the manipulated data is turned into strings, it's better to use PrintWriter. Because Printwrite is a subclass of a character stream, you can manipulate character data directly, and you can specify a specific encoding.

--------------------------------------------------------

PrintWriter : with the characteristics of PrintStream, but also has its own characteristics:

There are four destinations for this object: the 1:file object. 2: String path. 3: Byte output stream. 4: Character output stream.

use as much as possible during development PrintWriter .

The second parameter of the direct manipulation file in the method is the encoding table.

Direct operation of the output stream, the second parameter is automatic refresh.

Read the keyboard entry to turn the data into uppercase display in the console .

BufferedReader bufr = new BufferedReader (new InputStreamReader (system.in));// Source: Keyboard input

Purpose: Write the data to the file, and also want to refresh automatically.

PrintWriter out = new PrintWriter (new FileWriter ("OUT.txt"), true);//Auto Refresh after setting true

String line = null;

while ((Line=bufr.readline ())!=null) {

if ("Over". Equals (line))

Break

Out.println (Line.touppercase ());//Turn Capital output

}

Note:system.in,system.out these two standard input and output streams already exist when the JVM is started. Ready to use. When the JVM is over, the two flows are over. However, when the Close method that is displayed is used to close, both flows end prematurely.

Out.close ();

Bufr.close ();

Java.io.outputstream.PrintStream: Print Stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.