PrintStream (print output stream) and javaprintstream in JavaPrintStream in Java (print output stream)PrintStream is a print output stream that inherits from FilterOutputStream. PrintStream is used to decorate other output streams. It can be added to other output streams so that they can easily print various data value
above code is:Visible regardless of the data type, it is converted to a string, even the object is no exception.Here's another piece of code to learn about Java: System.out.println (); Out in the code, a PrintStream object in the System class, called the standard output stream object. The standard output stream object prints data to the console. Consult the API to see the following methods,static void SetO
This article extracts to: skywang12345
absrtact: introduces the meaning of each API of PrintStream, and analyzes the similarities and differences of PrintStream and DataOutputStream.
This chapter describes PrintStream and the difference between it and DataOutputStream. We first have a general understanding of PrintStream
PrintStream is actually a kind of filteroutputstreampublic class PrintStream extends Filteroutputstream implements Appendable, closeableDirectly known subclasses:LogStream is obsolete. No alternative versionPrintStreamPublic PrintStream (OutputStream out,Boolean AutoFlush) to create a new print stream.Parameters:Out-the output stream to which the values and objec
Print Flow ( PrintStream): The print stream can print any type of data, and the print stream will convert the data to a string before printingPrintStream can accept files and other byte output streams, so the print stream is an enhancement to the normal byte output stream, which defines a lot of overloaded print () and println () to facilitate the output of various types of data.PrintWriterPrintStream: is a byte print stream, and the system.out corres
In the entire java.io package, the print stream is the most convenient class for outputting information, consisting primarily of the byte print stream (PrintStream) and the character print stream (PrintWriter).
PrintStream and PrintWriter are both processing streams.
PrintStream
public class PrintStream
extends Filte
Package namespace; import Java. io. *; public class iotest {public static void main (string ARGs []) throws ioexception {bufferedreader bufreader = new bufferedreader (New inputstreamreader (system. in); printwriter PW = new printwriter (New bufferedwriter (New filewriter ("F: \ java.txt"); string line = NULL; while (true) {line = bufreader. readline (); If (line. equals ("over") break; PW. println (line); PW. flush ();} PW. close () ;}}/* both stream
First, the output of println () is platform-related. Depending on the machine running the code, the lines are sometimes separated by a newline, sometimes by a carriage return, or by a carriage return/newline pair. Writing to the console does not cause problems, but it is a catastrophe for network clients and servers that follow the exact protocol. Most network protocols, indicating that the carriage return/newline pair should be terminated. Using println () makes it easy to write a program that
usual time of the incoming path, according to the path output, But read it on the Bytearraystream.
Api:
System: In the facilities provided by the system class, there are standard inputs, standard outputs, and error output streams;
Out: "standard" output stream. This stream is open and ready to accept output data.
PrintStream: Adds functionality to other output streams so that they can easily print various data-value representations.
1 Packagefile;2 3 ImportJava.io.File;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 ImportJava.io.PrintStream;7 8 /*9 Print Stream: (PrintStream) converts any data into a string in print. Ten can also print objects, and collect log information One A - */ - the Public classDemo13 { - Public Static voidMain (string[] args)throwsIOException { - printtest (); - } + - Public Static voidPrinttest ()throwsIOExceptio
PrintStream and PrintWriter APIs are almost identical, and can output all forms of data in almost the same way
PrintWriter to accept writer parameters.
API comparisons:
So, what is the difference between them? From Stackflow
The main meaning is that 2 classes function basically the same, PrintStream can do printwriter also can be achieved, and PrintWriter function more powerful. But because PrintWrite
Because of the simplicity of printwriter, which requires only print () statements to output anything, there are a lot of times to use this class, but I often overlook the construction method: New PrintWriter (New FileOutputStream (), True);
If you
. FileOutputStream to obtain related file resources;
2) write data to the file through the write member method of java. io. FileOutputStream; in the middle, force the output through the flush member method of java. io. FileOutputStream;
3) Finally, call the close member method of java. io. FileOutputStream to close the file to release the system resources occupie
group. Aload_1 gets the data reference and puts it into the stack. Lastore stores integer values from the heap to the prime group and references the top of the current stack. The main () function is used to represent the dump () function. The parameter is the (row offset 23) that is prepared for the aload_1 command. Now we enter the dump () function.
public static void dump(int a[]){ for (int i=0; iPublic static void dump (int []); flags: ACC_PUBLIC, ACC_STATICCode: stack = 3, locals = 2, ar
, printstream );
Then, the program starts the thread:
Changetoz () method
The changetoz () method is similar to the changetoy () method. It starts from the input stream returned by changetoy:
Datainputstream yfileln = new datainputstream (inputstream );
The program creates a new pipeline:
Pipedoutstream pipeout2 = new pipedoutputstream ();
Pipedinputstream pipeln2 = new pipedinputsream (pipeout2 );
The thread sends the modified data (input stream pipe
printstream){This. xfileln = xfileln;This. printstream = printstream;}
The thread processes data through the run () method. First, read a row of data to make sure that the xstring is not empty and runs cyclically:String xstring = xfileln. Readline ();
Data is converted once each row is read.
String ystring = xstring. Replace ('x', 'y ');
Then, output the modifie
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.