File destinations - default path for non-image output files.

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

File destinations - default path for non-image output files.

Richard VanMetter
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?
     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.

Thanks in advance for any help.

Richard
Reply | Threaded
Open this post in threaded view
|

Re: File destinations - default path for non-image output files.

Rasband, Wayne (NIH/NIMH) [E]
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