Creating txt file from plugin

Im develping plugin and I know that I can log using f.e. IJ.showMessage("") etc.
But is there any simple way to open text file from imagej plugin and write data to it? If so, could someone help with the code for that?


it depends a bit on what you want to do exactly.

The IJ class provides convenience functions for saving: IJ.saveString to save text, and append to append to an existing file.

Example: grab the text of the log window and save it (Iā€™m copying from a jython file here but should be quite similar in Java):

if logdata is not None:
    IJ.saveString(logdata, "path/to/my/file/out.txt");

For more flexibility maybe java FileWriter is an option?

1 Like