On Sep 3, 2011, at 11:47 AM, Rich VanMetter wrote:
> In a plugin, it is often convenient to output a data file (not an image)
> related to an image file. The construction
>
> FileOutputStream file = new FileOutputStream("MyFile.dat");
> DataOutputStream disko = new DataOutputStream(file);
> disko.writeDouble(my_double);
> disko.writeInt(my_int);
> disko.writeBoolean(my_boolean);
> disko.close();
>
> works very well.
>
> However, depending on how I invoke ImageJ, it stores the file in
> different places.
>
> * If I invoke ImageJ from from the programs menu (via ImageJ.exe), the
> file is put in c:\Program Files\ImageJ.
> * If I open an image (by double clicking the image) which invokes
> ImageJ, the file is put in the same directory as the image.
> * If I open an image from within ImageJ, the file is put in the
> directory determined above.
>
> So clearly there is a default path being used, that depends on how
> ImageJ is invoked.
>
> My questions:
> How do I get() and set() that path?
Use full paths and you will not need to get() or set() the path.
> If I open an image within ImageJ, how do I get the path for that
> image? So I can put related files in the same directory.
You can get the directory that the current image was loaded from using
String dir = IJ.getDirectory("image");
-wayne