Java – why can’t I get filechannel from filewriter?
•
Java
I wonder why getchannel is only implemented in fileoutputstream instead of filewriter
Is there any real reason? Is there a way to lock the filewriter in another way?
Thank you
Solution
I suspect it's an oversight - note that filewriter is a subclass of outputstreamwriter and does nothing but pass fileoutputstream to the superclass constructor
Also note that you should hardly use filewriter because it does not allow you to specify encoding Instead, wrap fileoutputstream "manually" in outputstreamwriter – then you can also get the corresponding locked channel
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
二维码