title: JEdit Macro - Open and Save File
body: <p>I have a JEdit (BeanShell) macro which opens a specific file then immediately saves the file to my c:\temp folder (so that I don't accidentally update the real file).</p>
  <p>Here is the bean shell code:</p>
  <pre><code>logFilePath = &quot;c:\\temp\\aj.txt&quot;;
  jEdit.openFile( view , logFilePath );
  _buffer = jEdit.getBuffer(logFilePath);
  _buffer.save(view,&quot;c:\\temp\\backup.txt&quot;,true);
  </code></pre>
  <p>This gives me the following error:</p>
  <pre><code>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.  
  </code></pre>
  <p>I have tried adding a while loop to wait until <code> buffer.isLoaded() </code> is true, but that just goes into an infinite loop.<br />
  What does seem to work is popping up a message box (<code> Macros.message </code>).  However, I really don't want to have this unnecessary dialogue.</p>
  <p>I don't know much java, so please tell me if I'm making a rookie mistake.</p>
  <h2>Update:</h2>
  <p>Added my own answer to show the code pointed to from <a href="https://stackoverflow.com/users/34009/serhii">Serhii's answer</a>.</p>