All of the IO mechanisms in Java are input and output based on data streams that represent the flow sequences of character or byte data . So, what is data flow? A data stream is a collection of continuous data, like water in a water pipe, that supplies water at one end of a pipe , and a continuous flow at the other end of the pipe. A data writer can write data to a data flow pipeline in a paragraph or secti
) {
E.printstacktrace ();
}
}
}
Note that this is just a confirmation of System.out's overwrite behavior.
If you want to learn about IO, the polymorphism of the entire IO system needs to be understood to be very comfortable.
the read in the instance 7:system class
Copy Code code as follows:
Import java.io.IOException;
Import Java.io.InputStream;
public class Demo {
pub
stream that processes the stream instead of directly connecting to the data source or destination. Improve program performance by processing other streams.
? Relationship between node stream and processing stream:
The node stream is on the front line of io operations, and all operations must be performed by them. The processing stream can process other streams (improving efficiency or operational flexibility ).
System
Byte stream
? ByteArrayInutStr
Java IO (input output) stream 1. The buffer of the upstream stream 1. What is the buffer, also known as the cache, is a part of the memory space. That is to say, a certain amount of storage space is reserved in the memory space, which is used to buffer input or output data. This reserved space is called a buffer zone. The buffer zone is divided into the input buffer zone and the output buffer zone based on
OverviewBefore we learn the IO stream of Java, we need to know a few key words
Synchronous and Asynchronous (Synchronous/asynchronous): synchronization is a reliable and orderly operation mechanism, and when we perform synchronous operations, the subsequent task is to wait for the current call to return before the next step is performed, whereas async is the opposite Other tasks do not need to wait
data * 2, call the Write () method * 3, close the Stream object, call the Close () method, release the funding SOURCE */public static void main (string[] args) throws IOException {//File F = new File ("D:\\eclipse\\demo.txt");//FileOutput Stream fos = new FileOutputStream (f, true);//fos.write;//Fos.write (+);//Fos.write (48);//If you pass in a negative number, then go kanji// A Chinese character accounts for two bytes, one digit takes up one byte//b
must be a number"); Per = new person (name, age); // instantiate the person object try {fo. sav E (PER);} catch (exception e) {e. printstacktrace ();} system. Out. println ("Information modified successfully! ");} Public static void find () {fileoperate fo = new fileoperate (" D: \ test. per "); person per = NULL; try {per = (person) fo. load ();} catch (exception e) {e. printstacktrace ();} system. out. println (PER );}}
Compile the inputdata class
Import
After a day of study, the basic has a certain understanding of Java--io, and now share with you.Java. The IO package defines the types of multiple streams (classes or abstract classes) to implement input and output functions, which can be categorized from different angles:Can be divided into input stream and output stream according to different direction of data
The BufferedReader described in http://my.oschina.net/u/2263278/blog/508770 refers to one of its characteristics----when BufferedReader reads data from the input stream, if no valid data is read , where the program will block execution of the thread (using the Read () method of InputStream to fetch data from the stream, it will block the thread if there is no data in the data source), that is, the input stream described earlier, the output stream is blocked input, output. The traditional input a
to garbled; character streams are read by character and are typically used to read Chinese 3.) based on the Read method: node stream and cache stream three, BYTE stream Java.io.InputStream Java,io,outputstream1.fileinputstream class① the stream inherits from the InputStream used to read data from a file, its objects can be created with the keyword new.② Construction MethodYou can use the file name of a str
1, read/write (input/output) is for me, not for you to manipulate the object, such as reading the file is I read the file, for me is input, and I write files, for me is the output.2, Java IO uses the packaging mode, a flow wrapper another stream, to achieve better purposes. What is the rule of a flow wrapper for another flow? Use the byte stream to read the file, FileInputStream (new file ()), which you can
a general concept of performance optimization
It is generally believed that Java programs are always slower than C programs, and most people may have heard too much about this kind of advice. In fact, the situation is far more complicated than the old claims. Many Java programs are really slow, but slow speed is not an intrinsic feature of all Java programs. Many
());}}// Copy a fileElse {This. copyfile (source, DEST );}}// Delete files and foldersPublic void deletefield (string source ){File sourcefile = new file (source );// FolderIf (sourcefile. isdirectory ()){String [] names = sourcefile. List ();// Delete the subfiles and subfolders in the current folderFor (string name: names ){Deletefield (source + "/" + name );}// Delete the current folderSourcefile. Delete ();}// FileElse {Sourcefile. Delete ();}}// Cut the file and folderPublic void cutfield
Three classification methods of one Io stream:1. Score by Flow Direction:
Input stream: Only bytes of data can be read from it, and data cannot be written to itOutput stream: Only bytes of data can be written to and cannot be read from.
2. Data Types processed by the stream can be divided:
Byte stream: used to process byte data.
Bytes stream: used to process UNICODE character data.
3. The format can be divided:
Node stream (low-level stream): it can
=New A3 ();The path of the Cat.png picture in the computer D drive String filePath1 ="D:/cat.png";The path to the Cat.png picture in the E-drive of the computer String filePath2 ="E:/cat.png";Copy file A2.copyfile (filePath1, filePath2); }/** * File Copy *@param filepath_old: The path of the file to be copied *@param filepath_new: The path where the files are copied */PublicvoidCopyFile(String filepath_old, String filepath_new) {FileInputStream fis=null; FileOutputStream Fout =null;try {Instant
Original address: http://tutorials.jenkov.com/java-nio/nio-vs-io.htmlauthor : Jakob Jenkov translator : Guo proofreading: Fang FeiAfter learning the APIs for Java NIO and Io, a problem immediately poured into my mind:When should I use IO and when do I use NIO? In this article, I'll try to clearly parse the differences
();/* Registers the Selector on the server socket and sets the notification to accept the acceptance method.This tells selector that the socket wants to be placed in the ready table when the accept operation occursSo that multiple non-blocking I/O is allowed to occur. */Selectionkey Acceptkey = Ssc.register (Acceptselector,Selectionkey.op_accept);int keysadded = 0;The/*select method returns when any of the above-registered operations occur */while ((keysadded = Acceptselector.select ()) > 0) {A
(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}Results:Please enter what you want to write to the file: Enter E to finish your study, and keep up Hello java! end of file write !Test.txtABCDEFG Good study, Day day upWhen writing, if the file does not exist, the file will be created automatically, if it is not test
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.