我有一个JEdit(BeanShell)宏,它会打开一个特定的文件,然后立即将文件保存到我的c:\ temp文件夹中(这样我就不会意外更新真实文件)。

这是bean shell代码:

logFilePath = "c:\\temp\\aj.txt";
jEdit.openFile( view , logFilePath );
_buffer = jEdit.getBuffer(logFilePath);
_buffer.save(view,"c:\\temp\\backup.txt",true);

这给了我以下错误:

I/O Error
Each buffer can only execute one input/output operation at a time.  
Please wait until the current operation finishes 
(or abort it in the I/O progress monitor) before starting another one.  

我尝试添加一个while循环来等待 buffer.isLoaded() 为真,但这只是进入一个无限循环 似乎有用的是弹出一个消息框( Macros.message )。但是,我真的不想进行这种不必要的对话。

我不太了解java,所以请告诉我,如果我犯了一个新手的错误。

更新

添加了我自己的答案,以显示 Serhii的回答中指出的代码。

有帮助吗?

解决方案

您可以尝试此解决方案,并致电VFSManager.waitForRequests();

其他提示

本作品

这是 Serhii的答案指出的代码,上面是。

VFSManager.waitForRequests(); 命令后添加 jEdit.openFile()

完整代码

logFilePath = "c:\\temp\\aj.txt";
jEdit.openFile( view , logFilePath );

VFSManager.waitForRequests();

/* 
    VFSManager.waitForRequests();

    jEdit waits then for the file to be completely loaded before continuing 
    ... It's designed for waiting on all 'pending I/O requests'".
*/

_buffer = jEdit.getBuffer(logFilePath);
_buffer.save(view,"c:\\temp\\backup.txt",true);

你也可以不那么大胆。

  1. 使用jEdit.openFile()的返回值,这已经是Buffer,不需要getBuffer()
  2. 不要调用等待所有请求完成的VFSManager.waitForRequests(),只需将BufferListener添加到从jEdit.openFile()获取的Buffer中,并在此侦听器的bufferLoaded方法中执行save调用: - )
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top