使用 写入文件时OutputStream
,在该流关闭后,没有错误,它默默地写入失败。
开始:
self.outputStream = OutputStream(toFileAtPath: filePath, append: true)
self.outputStream.delegate = self
self.outputStream.schedule(in: RunLoop.current, forMode: RunLoopMode.defaultRunLoopMode)
self.open()
代表正在工作:
func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
//Will report that stream was opened.
...写一些文字-成功...
self.outputStream.close()
self.outputStream.write(newData, maxLength: newData.count)
没别的了。没有写入文本,但没有报告错误。
写入关闭的流不会触发错误吗?也就是说,我们应该在写入之前检查流状态吗?