• Post Reply Bookmark Topic Watch Topic
  • New Topic

Any Performance Optimization Tips for using NIO

 
mars76
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I read that Java1.4.x has got java.nio packages which provides better performance when compared to the old IO Packages.

Can any one tell me which existing classes of IO Can be replaed with the classes in NIO packages !!

Thanks
Sateesh
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.io classes actually use the NIO classes behind the scenes, so there's no replacement to be done. Unless, of course, you need the NIO-specific functionality like non-blocking IO or file locking.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In most cases it's as Joe says. On big exception is - if you want to copy bytes to or from a file - use FileChannel's transferFrom() or transferTo() methods. They are faster (typically) and easier to use than doing the same thing with streams. Which is unusual - typically the NIO stuff is harder to use, and only sometimes is noticably faster. (But sometimes it's a lot faster, so it may be worth investigating.) Note that if you're reading from a file using JDK 5.0 (cough), you can often use a Scanner to get the best of both worlds - fast NIO access combined with ease of use.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!