Detailed explanation of new I / O knowledge points of java7

This chapter focuses on the changed I / O API in the Java language, which is called "renewed I / O" or NiO 2 (jsr-203). NiO. 2 is a new set of classes and methods, which mainly exist in the java.nio package. Let's take a look at its advantages.

Let's look at the case first. The boss asked you to write a program to scan all directories on the production server and find out all property files that have been written with various read / write and owner permissions. For Java 6 (and earlier), this is almost impossible because:

NiO with Java 7 2 API can complete this impossible programming task. It supports direct navigation of directory tree (files. Walkfiletree(), 2.3 Section 1), symbolic link (files. Issymboliclink (), code listing 2-4), can read file attributes (files. Readattributes ()) in one line of code Section 3).

In addition, the boss also requires you not to interrupt the processing flow of the main program when reading these properties files. But the smallest properties file also has 1MB. Reading these files is likely to interrupt the main process of the program! Facing this requirement, in the era of Java 5 / 6, you are likely to use Java util. The classes in the concurrent package create thread pools and worker thread queues, and then use separate background threads to read files. As we will discuss in Chapter 4, concurrency in Java is still quite difficult and error prone. With Java 7 and NiO 2 API, you can use the new asynchronous filechannel (Section 2.5) to read large files in the background without specifying a worker thread or queue. Whew!

This new API is very useful. Although it can't make coffee for you, its development trend is there.

The first trend is the exploration of other data storage methods, especially in the field of non relational or large data sets. You may soon encounter the problem of reading and writing large files (such as large report files on microblog). NiO. 2 can help you read and write large files in an asynchronous and effective way, and take advantage of the characteristics of the underlying operating system.

The second trend is the development of multi-core CPU, which makes real concurrent and faster I / O possible. Concurrency is a difficult area 2, but NiO 2 will help you. It provides a simple abstraction layer for multithreaded file and socket access applications. Even if you don't use these features directly, they will have a great impact on your programming career, because they are widely used in ides, application servers and various popular frameworks.

It delves into the subtle complexities that concurrent computing can bring to your programming career.

These are just NiO 2 examples of what will help you. If NiO 2 can solve some of the problems you are facing. The content of this chapter is for you! Otherwise, you

You can come back when you receive a Java I / O task.

In this chapter, you will experience the new I / O capabilities of Java 7 so that you can start writing NiO based 2 code and have the confidence to explore new APIs. In addition, these APIs use some of the features mentioned in Chapter 1, which proves that Java 7 does use its own features.

We think you are likely to use the new file I / O capability, so this chapter will introduce it in great detail. You need to start by understanding the new file system abstraction layer, that is, first understand path and its auxiliary classes. On path, you will be exposed to common file system operations, such as copying and moving files.

The above is all the knowledge points of java7 I / O. thank you for your learning and support.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>