1. Print Flow(1) Classification:• Byte print stream PrintStream • character print stream PrintWriter(2) Characteristics of the print flow:• can only write data , cannot read data• Only the destination can be manipulated and the data source cannot be manipulated • can manipulate any type of data • automatically refresh if automatic refresh is enabled • the ability to manipulate text files directly(3) Att
A good memory is better than a pen.Note: Inputstream/outputstream is an abstract class, cannot be instantiated, can only instantiate its subclasses, and is a byte stream, not a string
InputStream is = new FileInputStream ("A.txt"); Equivalent to InputStream is = new FileInputStream (New File ("A.txt"));
OutputStream similar to the same,
Package com.
Ckinghan.outputstream;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Ja
(1) node stream: A stream class that reads and writes from a specific place, such as a disk or a memory area.Filter stream: Use the node stream as the input or output. A filter stream is created using an existing input stream or o
1 Packagefile operation;2 3 ImportJava.io.File;4 ImportJava.io.FileReader;5 Importjava.io.IOException;6 ImportJava.io.Reader;7 8 Public classTestreader {9 Public Static voidMain (string[] args)throwsIOException {TenFile file=NewFile ("D:" +file.separator+ "Test.txt"); One /*File*/Reader reader=NewFileReader (file);//you can also receive instantiated objects directly with a variable of type FileReader, without using an upward transformation. A if(File.exists ()) { -
One.For buffers, also classified, buffered read and buffered write. Now explain the buffer write.Why there are bufferwriter such objects exist, that is, the previous ch,buf and other things and flow objects together, so that they become a whole.By incorporating the buffered functionality, the stream object is really an efficient object class.Strangely, there is no buffer used to write the writer character stream
Java IO stream data stream transmissionYou can use this as a formula.//Data Flow TransmissionImportJava.io.*; Public classindex{ Public Static voidMain (string[] args)throwsexception{//You can use this as a formula.//no memory .Bytearrayoutputstream Zjszl =NewBytearrayoutputstream (); DataOutputStream SJL=NewDataOutputStream (ZJSZL); LongAA = 123456789;
1. Introduction of NiO (New io stream)JDK4 appears nio. The new IO and the traditional IO have the same purpose, are used for the input and output, but the new IO uses a different way to handle the input and output, in a memory-mapped file, the file or a section of the file map into memory, you can access the same memory as a visiting file, This is much more efficient than the old Io, but there are a lot of places where we see the old IO reference, so
One.After you have finished writing, read it. Now the object being explained has changed from FileWriter to FileReader, from output to input.The explanation of Io flow is always around the character stream, and the foothold is also the two specific subclass object in the character flow.The reader object's methods are described in various ways of reading.The read exception is described.Write the program completely and the results are as follows. When r
be updated and must be closed and re-established OutStream=NewFileOutputStream (FilePath); //OutStream = new FileOutputStream (new File (FilePath)); If the passed parameter is true, then the original file continues to be written, instead of overwriting the source file. //OutStream = new FileOutputStream (FilePath, true); //OutStream = new FileOutputStream (new File (FilePath), true);Outstream.write (Bytearr); } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvy2pjmjexmziy/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>Import java.io.*;p ublic class bufferdemo{public static void Main (string[] args) throws Ioexception{bufferedreader buf= Null;buf=new BufferedReader (New InputStreamReader (system.in)); System.out.print ("Please enter a number:"); String Str=buf.readline ();//parses the string to an integer int i=integer.parseint (str); i=i+10; SYSTEM.OUT.PRINTLN ("The modified
FileOutputStream (file); 3. Start writing data, int a = 10; int Type 4 bytes outputstream.write (a); Note that only one byte outputstream.write (' B ') can be exported at a time.
Char type Outputstream.write (5); 0000-0000 0000-0000 0000-0001 1111-1111 = = 511 int b = 511; Greater than eight-bit (9-bit) outputstream.write (b); The actual result is 255, but the int c = 63 is not shown; Less than eight bits (6 bits) Outputstream.write (c);
Garbled//4. Close resource Outputstream.close (); }
1. In fact, the byte stream itself does not use a buffer (memory) during operations, but directly operates on the file itself. The swap stream uses a buffer during operations and operates through the buffer zone.Composition. That is, the byte stream uses a buffer while the byte stream does not.2. all files are stored i
value.optionalIt should be noted that accumulator should meet the binding (associative).ToArray ()Places the elements in the stream into an array.CombinationThe concat is used to connect two streams of the same type.public static “TransformationThe ToArray method converts a stream into an array, and if you want to convert to another collection type, the West needs to call the Collect method and use the Col
tool library for us to quickly create a Collector. As we have learned earlier, the collector function must meet the identity constraints and related item constraints. The following constraints must be observed when you create a Collector in a library that is simplified based on Collector (for example, Stream. collect (Collector:Convert to another set
Many Stream
specified byte array to this output stream.
Other common methods:
Void close (); // close the output stream and release all system resources related to the stream.
Void flush (); // refresh the output stream and forcibly write all buffered output bytes.File input and output streams:
FileInputStream and FileOutputStrea
bits) for Chinese characters. UTF-8 contains all the characters needed by all countries in the world, is an international code, universal.
20. Change the standard input/output device
The System class in the java. lang package contains the setIn and setOut methods, which are used to re-allocate standard input streams and output streams respectively.1 import java. io. *; 2 public class TransStreamDemo5 3 {4
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.