The method of accessing files by using the files tool class and path interface of Java 7

In the Java version of date, files are accessed through the file class, but the operation of the file class is limited, it can not take advantage of the characteristics of a specific file system, and the performance is not high. In case of access error, many of them directly return false without giving exception information. Therefore, Java 7 adds two tool classes, files and paths, to operate files. The files class contains a large number of static methods to manipulate files. Java 7 also introduces a path interface, which represents a platform independent path. Its usage will be described in detail below.

Paths provides two methods to obtain the path object,

1、get(URL url)

2. Get (string first, string... More), which is a method to splice multiple strings into a path

Here is the test code

Run the above program, and you will see the following results

The following is the modified time attribute of the modified file

The above method of accessing files using java7's files tool class and path interface is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.

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
分享
二维码
< <上一篇
下一篇>>