What is the exact use of java nio package when already methods are available with io package

前端 未结 5 1198
清歌不尽
清歌不尽 2020-12-12 20:43

I was learning java nio package and I realized there are lots of methods already provided by File which nio.Files is providing again by using Path class. Like that few more

5条回答
  •  误落风尘
    2020-12-12 21:20

    Almost every method in java.io.File has issues that cannot be fixed for compatibility reasons, the most obvious is that the methods return a boolean when they fail. These issues plus the desire to support pluggable file systems and many other things necessitated the development of a completely new file system API so this is why java.nio.File was created.

提交回复
热议问题