如何在操作脚本 3 中解决文件流"Error #3013: File or directory is in use"?



我知道许多用户已经问过这种类型的问题,但这并没有解决我的问题。

我正在使用FileStream在文件中写入一些内容,以下是我用来执行此操作的代码:

var fs:FileStream = new FileStream ();
fs.open( f , FileMode.WRITE ); // f is contains the file path
fs.writeBytes ( fzf.content ); // fzf is a FZipFile which contains some content
fs.close ();

但是问题是,最初,如果我编写文件,那么它可以完美地工作,但是如果我试图编写另一个文件,则不关闭应用程序,则显示错误" 文件或目录正在使用"在fs.open行,所以我不知道我在编写写作方法后打电话给close()时在哪里做错。

如果有人可以找到我在做错的地方或如何解决此问题,请帮助我解决。

您正在尝试一个又一个地保存文件,对吗?如果是这样,则出现此错误,因为在尝试编写下一个文件之前,文件未足够快地关闭。您应该使用openasync((而不是open((,然后在文件流上聆听event.close事件(仅在异步模式下触发(。触发时,您可以写下下一个文件:

var fs:FileStream = new FileStream ();
fs.addEventListener(Event.CLOSE, onFileClosed);
fs.openAsync( f , FileMode.WRITE ); // f is contains the file path
fs.writeBytes ( fzf.content ); // fzf is a FZipFile which contains some content
fs.close ();
private function onFileClosed(e:Event):void
{
    // The file was closed succesfully, it is now safe to write the next one
}

相关内容

最新更新