FileChannel#force是否等同于OutputStream#flush?我总是要打电话吗?

时间:2016-01-18 16:21:12

标签: java nio filechannel

我的课程类似于cb.equal(contract.get(Contract_.provider), provider);

FilterOutputStream

当我传递public class WritableFilterChannel implements WritableChannel { public WritableFilterChannel(final WritableByteChannel channel) { super(); this.channel = channel; } // isOpen(), close() delegates to the channel // write(ByteBuffer) overridden to work differently protected WritableByteChannel channel; } 的实例时,除了FileChannel之外无法force()

close()是否等同于FileChannel#force?我总是要打电话吗?

我必须这样做吗?

OutputStream#flush

1 个答案:

答案 0 :(得分:1)

"等效"太强大了。 angular.module('myApp').directive('myDocumentClick', ['$window', '$document', '$log', function($window, $document, $log) { return { restrict: 'A', link: function(scope, element, attrs) { $document.bind('click', function(event) { $log.info(event); if (angular.element(event.target).hasClass('myClass')) { $window.alert('Foo!'); } }) } }; } ]); FileChannel.force(false)类似。 FileChannel的force()方法在返回文件后提供了比OutputStream的flush()方法更强的保证。

显然,您不必关闭()您调用force()方法的FileChannel。您应该只在完成频道后关闭频道。但是,无法保证关闭通道将导致相当于强制操作。如果您需要force()指定为通道闭包的一部分的行为,那么您必须以close()方法中的方式显式调用它。

相关问题