java - Are ReadableByteChannel and WritableByteChannel a replacement of InputStream and OutputStream? -
java - Are ReadableByteChannel and WritableByteChannel a replacement of InputStream and OutputStream? -
as far know, readablebytechannel
, writablebytechannel
nio
bundle can considered replacement of inputstream
, outputstream
legacy io
package. if fact, can used same i/o operations , more.
nevertheless, still seem not much used. also, back upwards in popular libraries quite poor. example, guava team thinking dropping it.
is there reason new code dealing i/o utilize streams respect channels?
there historical context should not ignored. when nio introduced (back in java 1.4), lot of features missing , promise hand them in later not hold long time. recall in java 1.4 way filechannel
first create fileinputstream
, fileoutputstream
, or randomaccessfile
, invoke getchannel
on it. thus, there no way write code using nio/channels without using older io/stream api.
the first java version providing way create filechannel
without using old api java 7. first version providing nio api directory scan, alter notifications , advanced file attributes.
so nio api can considered quite new regarding these features , it’s not surprising takes time developers adopting it. way, kind of adoption might include removing utility methods became unnecessary new api proposal have linked. far can see means removing 4 methods functionality trivial when using recent api.
obviously, when want utilize 1 of newer features memory mapping or java 7 features named above have utilize nio api. on other hand, when want utilize serialization or zip/gzip (de)compression channel support, java offers, wrap channel stream…
java io nio
Comments
Post a Comment