Introduction to Java IO stream-nio

Source: Internet
Author: User

2017-11-05 22:09:04

    • Nio

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.