Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O vs NIO  RSS feed

 
Puspender Tanwar
Ranch Hand
Posts: 471
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am reading I/O and NIO from last 10 days, yet it is confusing to me. don't know why i am still confuse. actually i am not getting that ,where i am, what i have learned and what i have to learn next.
some questions i my mind..
1. why NIO was invented
2. according to IO NIO tutorial on doc.oracle, they have performed almost every operation by using Files class in java.nio.file package . is that true that Files class alone have all the capabilities performed by java.io package.
3. which option is better for use, IO or NIO ?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were explicitly mentioning java.nio.file: The original API for working with files and file systems (class java.io.File) was lacking features that people needed, for example for working with file attributes (whether file are read-only etc.), symbolic links, and watching file systems for changes. Those new features and many more were added with the interfaces and classes in the java.nio.file package.

My opinion is: if you're writing new code, try to use the NIO API for files instead of the old API. This starts at using java.nio.file.Path instead of java.io.File.

Besides new APIs for working with files and file systems, the java.nio package contains much more. The most important part of it are interfaces and classes that make it possible to do asynchronous and non-blocking I/O, which is necessary for creating high-performance and scalable server systems in Java.

Programming with asynchronous and non-blocking I/O is a lot harder than using plain old simple synchronous, blocking I/O, and you don't need to make your program asynchronous and non-blocking unless there's a specific need to do so.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!