2017-11-05 22:09:04
NIO: New IO is the meaning of JDK4, new IO, new IO and traditional IO have the same purpose, are used for input and output, but the new IO uses a different way to handle the input and output, in the way of memory mapped files, Mapping a file or a section of a file to memory allows you to access the file as if it were in memory, which is much more efficient than the old IO , but there are many places where we see the old IO as the main.
A small example:
Path: Paths
Paths: There is a static method that returns a path
Public static Path get (URI uri)
Files: Provides a static method for us to use
Public static long copy (Path source,outputstream out): provides replication functionality
public static path Write (path path,iterable<? extends charsequence> Lines,charset CS): writes the collection to the file
public class Demo7 {public static void Main (string[] args) throws IOException { //A statement completes the copy function files.copy (Pat Hs.get ("E:/test.txt"), New FileOutputStream ("E:/copy2.txt")); A statement completes the collection of storage work arraylist<string> array = new arraylist<> (); Array.add ("Hello"); Array.add ("World"); Array.add ("!"); Files.write (Paths.get ("E:/array.txt"), Array, Charset.forname ("GBK"));} }
Introduction to Java IO stream-nio