Login  Register

Re: problem with text file output

Posted by Michael Schmid on Jun 18, 2015; 4:12pm
URL: http://imagej.273.s1.nabble.com/problem-with-text-file-output-tp5013208p5013210.html

Hi Michael,

you have to use the *result* of File.open as the first argument of the print function (not the path to the file).
See this example macro
  http://rsb.info.nih.gov/ij/macros/SaveTextFileDemo.txt

Michael
________________________________________________________________
On Jun 18, 2015, at 17:38, Cammer, Michael wrote:

> I am having a problem and don't know if I'm overlooking something obvious or if there is a bug in the daily build (updated a few minutes ago).
>
> The following code opens a new text file in the correct location and the Debug window shows correctly
> outputFile (g)    *             "G:\VickieTest\file_one-2_results.txt"
> (Yes, I know the getTitle is redundant, but I cut and pasted from somewhere else.)
>
>      currentpath = openPath + fileList[dir];
>      currentList = getFileList(currentpath);
>      //Array.show(currentList);
>      filecount = 0;
>      while ( !(endsWith(currentList[filecount], ".tif")) ) {
>        filecount++;
>      }
>      open(currentpath + currentList[filecount]);
>      title = getTitle();
>      print(title);
>      newTitle = replace(title, ".tif", "_results.txt");
>      outputFile = openPath + newTitle;
>      File.open(outputFile);
>
> However, the file remains empty even though there are a series of print commands such as these:
>
>      print(outputFile, title);
>      print(outputFile, outputString);
>
> The macro then crashes with the command
>
>      File.close(outputFIle);
>
> The file cannot be deleted in Windows because it is still open.
>
> Any help appreciated.
>
> Thanks.
>
> =========================================================================
> Michael Cammer, Microscopy Core & Skirball Institute, NYU Langone Medical Center
>                      Cell:  914-309-3270     ** MY OFFICE HAS MOVED TO SKIRBALL 2nd FLOOR, Back right **
>          http://ocs.med.nyu.edu/microscopy & http://microscopynotes.com/
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html