像标题一样; 关闭FileChannel基础文件流吗?
从AbstractInterruptibleChannel.close()API文档中,您可以阅读:
关闭此频道.
如果通道已经关闭,则此方法立即返回.否则,它将通道标记为已关闭,然后调用该
implCloseChannel方法以完成关闭操作.
哪个调用AbstractInterruptibleChannel.implCloseChannel:
关闭此频道.
close方法调用此方法以执行关闭通道的实际工作.仅当通道尚未关闭时才会调用此方法,并且永远不会多次调用此方法.
此方法的实现必须安排在此通道上的I/O操作中阻塞的任何其他线程立即返回,方法是抛出异常或正常返回.
这并没有说明关于流的任何事情.事实上,当我这样做时:
public static void copyFile(File from, File to)
throws IOException, FileNotFoundException {
FileChannel sc = null;
FileChannel dc = null;
try {
to.createNewFile();
sc = new FileInputStream(from).getChannel();
dc = new FileOutputStream(to).getChannel();
long pos = 0;
long total = sc.size();
while (pos < total)
pos += dc.transferFrom(sc, pos, total - pos);
} finally {
if (sc != null)
sc.close();
if (dc != null)
dc.close();
}
}
Run Code Online (Sandbox Code Playgroud)
......我把溪流打开了?
use*_*421 19
答案是"是",但Javadoc中没有任何内容实际上是这样说的.原因是它FileChannel本身是一个抽象类,它的具体实现提供了implCloseChannel()关闭底层FD的方法.但是由于该体系结构和implCloseChannel()受保护的事实,这没有记录.
| 归档时间: |
|
| 查看次数: |
3659 次 |
| 最近记录: |