O & network IO

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/jinknow/article/details/80274980

Java all the equipment in the data abstraction into an orderly flow model.

Input & output stream stream (in view of memory to run), the byte stream (the InputStream) & character stream (Reader / Writer), the node processing flow stream {& Decorator: using the processing flow streams to different nodes package]

 

Redirection System.setErr (); System.setOut (ps); System.setIn (fis);

RandomAccessFile

Not only can read the contents of the file, you can also export data to a file. "Random access", can jump directly to read and write data to the file anywhere, so that only part of a file access, rather than start to end, select RandomAccessFile.

Direct file read and write, can not read and write other IO nodes.

RandomAccessFile raf = new RandomAccessFile("a.java”, “rw”);// r   rw   rws  rwd

raf.getFilePointer();    raf.seek(raf.length() ); raf.write();

RandomAccessFile not specify the location of the insertion content (overrides) to a file, only the last additional content, how? Insertion point behind the first content read into the buffer, writes the contents of the file and then inserted into the contents of the buffer is appended to the file.

NIO.2

java7 the original NIO major improvements:

a) providing a comprehensive file IO and file system access support: new java.nio.file package and all sub-package

b) Channel-based asynchronous IO (NIO.2): Add to a plurality Channel interfaces and classes at the beginning of the Asynchronous packet java.nio.channels

Introducing Path interfaces, the platform represents the path to a platform-independent. Files tools manipulate files, Paths tool class two static methods Path of return.

FileVisitor file and directory traversal (SimpleFileVisitor) Files.walkFileTree ()

WatchServie monitor file changes Path.get ( "C: /"). Register (watchService,)

Tools under the Access file attributes java.nio.file.attribute package

Guess you like

Origin blog.csdn.net/jinknow/article/details/80274980