Problem in saving file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem in saving file

gary.chien
Hi,
I got a problem in in running my Macro
A window showed up as following:
 
FileSaver.saveAsTiff.
File saving error(IOException):
D:\Sample\temp\Blue.tif("File can not be opened, because it is already in use")(translated from Mandarin)
D:\Sample\temp\Blue.tif

path:D:\Sample\temp
file:Blue.tif

But the error showed up sometimes! (randomly about 10%)
I just wounder if the Macro might go wrong if it reads and opens too frequently, because it runs successfully in most of the time...
Any suggestion will be appreciated.

BRs
 
Gary
Reply | Threaded
Open this post in threaded view
|

Re: Problem in saving file

Michael Schmid
Hi Gary,

just a thought, not any definitive answer:

Could it be that you close a file and then write a file with the same name rapidly in succession?
It may depend on details how the file was open before, but some file operations may be done asynchronously while the program continues. Then closing the old file would not be finished at the time when you want to write a new file with the same name.

If this is the case, and as it seems that you are working on a temporary file, maybe you can switch between two different file names? E.g. close file Blue1.tif, then write Blue2.tif, close Blue2.tif and write Blue1.tif. Or do the same with two different directories temp1 and temp2.

Michael
________________________________________________________________
On Dec 2, 2015, at 12:21, gary.chien wrote:

> Hi,
> I got a problem in in running my Macro
> A window showed up as following:
>
> FileSaver.saveAsTiff.
> File saving error(IOException):
> D:\Sample\temp\Blue.tif("File can not be opened, because it is already in
> use")(translated from Mandarin)
> D:\Sample\temp\Blue.tif
>
> path:D:\Sample\temp
> file:Blue.tif
>
> But the error showed up sometimes! (randomly about 10%)
> I just wounder if the Macro might go wrong if it reads and opens too
> frequently, because it runs successfully in most of the time...
> Any suggestion will be appreciated.
>
> BRs
>
> Gary

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Problem in saving file

gary.chien
Hi Michael,

Thank you for the hint.
 
In my previous Marco version, a photo was processed sequentially and saved about 5 times in a round, and totally 200 loops for whole photos. It did everything OK till I made more processing step(including saving file) up to 10, then the error showed up sometimes.

Maybe too many files there that can not be closed completely before next loop.
I will try the method based on your tip or just make another "close all" before next loop.
Hope that will work out.

Thanks for the help!!

BRs
Gary